Hide price in Bigcartel? - bigcartel

I'm trying to hide the price of certain products on my bigcartel site, as well at the "coming soon" text. I'm using the Sidecar theme. I tried using code someone posted here several years ago for this, but nothing has worked. Can anyone help me? Thank you in advance.

The following code is the easiest way to hide both of these:
div.product-price { display: none; }
div.status-text { display: none; }
Go to Design > Code > Custom CSS
Unfortunately, on some themes a boxed background for coming soon / sold out stays.

unless to the rescue !
Create an [145758, 9675466, 6872210] array with product Ids that not to show price and comming soon.
you can find product id by product.id
{% assign productIds = "145758,9675466,6872210" | split: ',' %}
unless print only if constrain is not met.
This prints nothing:
{% unless input contains '145758' %} Your comming or price HTML code block here {% endunless %}
This prints "Your block html code":
{% unless input contains '444444' %} Your comming or price HTML code block here{% endunless %}

Related

How to make a for loop break on counter in Django Templates?

How can I make the for product in products loop break after the if condition is fulfilled 3 times. I have been trying to set up a counter but that isn't working... because set is not accepted inside of for loops. Though testing it out a bit more it isn't being accepted anywhere.
When I use set it throws this exception or a variation of it: Invalid block tag on line 11: 'set', expected 'endblock'. Did you forget to register or load this tag?
I am aware that I should put all the logic I'm using Templates for inside of the view and then pass it through the dictionary but it would take too much time to research everything about that and i just want to be done with this.
Honestly I am really tired it is 6am and idk what to do. Thank you for your help in advance. :)
Edit: I know I have to use namespace() for set to be able to propagate across scopes. But set itself is still raising the same exception as above.
Edit2: I thought that django uses jinja2 as it's templating language but it seems like that is not the case. I fixed the mentions of jinja2 as I haven't changed any of the defaults that come with a fresh install of django.
HTML
{% for category in categories %}
<div>
<h5 class="text-line"><span>{{category.name}}</span></h5>
</div>
<!-- Cards Container -->
<div class="shop-cards">
{% set counter = 0 %}
{% for product in products %}
{% if product.category.categoryID == category.categoryID %}
<!-- CARD 1 -->
<div class="card">
<image class="product-image" src="{% static 'images/product-4.png' %}"></image>
<div class="card-category-price">
<h3 class="product-name">{{product.name}}</h3>
<h3 class="product-price">{{product.price}}</h3>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
You can't (by design).Django is opinionated by design, and the template language is intended for display and not for logic.
You can use Jinja instead.
Or, you can do the complicated stuff in Python and feed the results to the template language through the context. Bear in mind that appending arbitrary objects to a list in Python is a cheap operation. So (in a CBV) something like
context['first_three'] = self.get_first_three( whatever)
...
def get_first_three(self, whatever):
first_three = []
for obj in ...:
if complicated stuff ...
first_three.append( obj)
if len(first_three) == 3:
break
return first_three
BTW you can't (easily?) implement break in Django templating, but you can easily give it the ability to count:
class Counter( object):
def __init__(self):
self.n = 0
def value(self):
return self.n
def incr(self):
self.n += 1
return ''
In the context pass context['counter'] = Counter()
In the template refer to {{counter.value}} as much as you want, and in a conditional where you want to count occurences, use {{counter.incr}}. But, it's hacky, and probably best avoided.
The problem seems to arise due to a misconception of the templating functionality. It is to be used mainly for display purposes and not filtering purposes, and you are facing a filtering problem:
I want to filter the 3 first elements of a list that fulfill a specific condition
is your main issue and templating frameworks will be poor at solving your issue, whereas this is exactly what python and Django's ORM are good at.
Why don't you first filter in Django, then display in template? For example as follows:
...
products = queryset.filter(abc=condition)[:3]
context = Context({ 'products': products })
return HttpResponse(template.render(context))

how can I add more character space to the home page tagline in big cartel?

Does anyone know how to edit the CSS in a Big Cartel theme (specifically the FOUNDRY theme) to allow for more text in the home page tagline? Currently, you can only type about 100 characters. I would like to be able to write a bit more (like a small paragraph about the shop and current product overview).
The text box is limited to 100 characters, so to edit that you'll need to change the code the Advanced > Home section of the Customize Design area. Find this code at the top:
{% if theme.home_tagline != blank %}
<div class="home_tagline">
{{ theme.home_tagline }}
</div>
{% endif %}
And replace the {{ theme.home_tagline }} with your own text.

How to Repeat Parts of Jinja2 Template

I realize a couple of similar questions on this have been asked, but they don't relate specifically to what I'm trying to do and I'm pretty much a total beginner, so the answers seem more advanced than what I think I'm expected to do.
I'm working on implementing a Jinja2 template with Python code into an html page of notes I've been keeping while taking this course.
So...
The html block I'm trying to template and repeat has the following structure:
<h1>Stage Number</h1>
<div class = "lesson">
<h2>Lesson Number</h2>
<div class="concept">
<div class="concept-title"> Title </div>
<div class="concept-description">
<p>Description paragraph</p>
<p>Description paragraph</p>
</div>
<div class="concept-title"> Title</div>
<div class="concept-description">
<p>Description paragraph</p>
</div>
</div>
</div>
For each stage, lesson numbers vary and each title has a varying number of description paragraphs.
My code is on Github (this is an edited version): https://github.com/graceehayden/Stage4Udacity-Session-2/blob/master/templates/index.html
My main.py file has the template code, which is supposed to be implemented in the index.html file.
The course just sort of went over the edge on me and re-watching videos or finding other YouTube tutorials on templating isn't helping because a lot of it is more advanced than I seem to be at this point.
Any help or pointers on how to straighten the variables out so they correlate properly with the index.html file would be so appreciated. When I pretend I don't have so many inputs, I am able to make a simple single variable work and show up when I run the app, but with the complexity I have now and need, it isn't functioning.
It looks like you mostly have the right idea with the code so far.
The big thing that is missing is that you need data types that are sequences to extend this to do what you want here.
Each lesson has a list of concepts with an associated description.
concept1 = {
'name' : 'concept1',
'description1' : 'This is the description for concept1!',
}
lesson1 = {
'name' : 'lesson1',
'concepts': [concept1, concept2] #the list here lets us have more than one value
}
Then each Stage is a data structure that contains a list of different lessons.
stage1 = {
'name' : 'stage1',
'lessons': [lesson1, lesson2],
}
Finally you stuff all these different stages into the template_values
template_values = {
'stages' : [stage1, stage2],
}
Then you need the templating to access the nested data:
{% for stage in stages %}
//do things with this particular stage
{% for lesson in stage['lessons'] %}
//do things with this lesson
{% for concept in lesson['concepts'] %}
//do things with individual concepts
{% endfor %}
{% endfor %}
{% endfor %}
Note: haven't tested the template yet, so might have made some mistakes accessing the dictionary.

Render simple two row table in TWIG template - Symfony2

This question is terrible basic, but I tried to find out the answer both on the Symfony documentation as well as in forums and tutorials but everyone does it differently and no solution seems to work with my code.
I just need to render two columns of data with a TWIG template. It has to show the messages sent from a contact form where the only fields are the email of the sender and the body of the message.
The Entity for this is named as Enquiry.
The member function is as follows:
public function showAction()
{
$enquiry = $this->getDoctrine()->getRepository('MyWebSiteBundle:Enquiry')->findAll()
if (!$enquiry) {
throw $this->createNotFoundException(
'No elements found'
);
}
return $this->render('MyWebSiteBundle:Page:admin.html.twig', array('object' => $enquiry));
}
And the part to the template which is supposed to show the result looks as follows:
{% for item in object %}
{{ item.email }} - {{ item.body }} <br>
{% else %}
<h2>Aoutch ! No data !</h2>
{% endfor %}
Thank you very much in advance I will be much relieve to find the answer to this.

Django template: Ordering dictionary items for display

I am making a website that displays a user's chosen youtube videos. A user can enter a comment for each video.
I want to display (in this order):
User comment
video title
I have already made the view and have created the following list of dictionary items. Each one represents one video. I send this to my html page:
[
{"my_own_object": vid_obj1, "youtube_obj": obj1}
{"my_own_object": vid_obj2, "youtube_obj": obj2}
]
"youtube_obj" is the object supplied by youtube, which contains the url, title, rating, etc. "my_own_object" contains the user's comments as well as other information.
I iterate over the list and get one dictionary/video. That's fine. Then I need to display the video's information:
{% for key,value in list.items %}
{% if key = "my_own_object" %}
<div>
<p>{{value.user_comment}}</p>
</div>
{% endif %}
{% if key = "youtube_obj" %}
<div>
<p> {{value.media.title.text}}</p>
</div>
{% endif %}
{% endfor %}
This works, except that, because I cannot determine the dictionary order, I might end up with:
Video title
User comment
I thought I could get around this by assigning variables (and then printing the values in the proper order), and am still reeling from the fact that I cannot assign variables!
So, how can I get around this? Can I pluck the key/value that I need instead of iterating over the dictionary items - I tried looking for ways to do this, but no luck. Any other ideas? (I need to pass both video objects as I may need more information than comment and title, later.)
You can use dictionary keys directly:
{% for item in list %} {# PS: don't use list as a variable name #}
<p>{{item.my_own_object.user_comment}}</p>
<p>{{item.youtube_obj.media.title.text}}</p>
{% endfor %}
Just iterate twice. Once for the videos, and once again for the comments. Or, split them into their own dictionaries that are passed through to the template. That's probably a better option, as you avoid iterating twice over the dict. For very small dicts this will be no problem. For larger ones, it can be a problem.