I have been trying to do this forever it seems.
I don't understand what to put in the templates and can find no guidelines help.
My Profile page
need friends list
something like:
{% for friends in Friendship.objects%}
<li>are_friends: {{ friends.are_friends.user.username}}</li>
<li>is_invited: {{ friends.is_invited}}</li>
{% endfor %}
Well being a bit of newcomer to Django and programming in general this took me ages to work out but I got there in the end so Ill share what I did. First of all though the code might no be exactly what you need but you will get the idea. I also might have made some mistakes here or there is better way to do it so don't assume this is the most correct way but it does work.
First of all I split my code into two templates. One for when I am on the profile page of another user and one for when I am on my "Manage my Friends" page. Please bare in mind this is basically pure template code and there has been no stylings applied. Thats up to you to do.
{% if user|friends %}
{% with user|friends as list %}
Friends List
{% for m in list %}
{{ m }}
{% endfor %}
{% endwith %}
{% else %}
Search for Friends
{% endif %}
{% if user|friendshiprequests %}
{% with user|friendshiprequests as list %}
{% if list.received %}
Friendship Requests Received
{% for m in list.received %}
{{ m }}
Accept Request
Decline Request
Block User
{% endfor %}
{% endif %}
{% if list.sent %}
Pending Friend Requests Sent by You
{% for m in list.sent %}
{% if not user|isblockedby:m.to_user %}
{{ m.to_user }}
Cancel Request
{% endif %}
{% endfor %}
{% endif %}
{% endwith %}
{% endif %}
{% if user|blocks %}
{% with user|blocks as list %}
{% if list.applied %}
List of Blocked Users
{% for m in list.applied %}
{{ m }}
{% endfor %}
{% endif %}
{% endwith %}
{% endif %}
For the profile page of another user I have the following code. Bear i nmind I have a profile application which is passing in the username of the profile I am looking at and want to interact with. You may need to find another way to do it.
{% if not user == profile.user %}
{% if not user|isblockedby:profile.user %}
{% if not profile.user|isblockedby:user %}
{% if not user|isfriendswith:profile.user %}
{% if not profile.user|isfriendshiprequest:user %}
{% if user|isfriendshiprequest:profile.user %}
You have already sent a friend request
Cancel Friend Request
{% else %}
Send Friend Request
Block User
{% endif %}
{% else %}
{% endif %}
{% else %}
You and {{ profile.user}} are friends
trans Unfriend
Block User
{% endif %}
{% else %}
You have blocked this User
Unblock User
{% endif %}
{% else %}
You have been blocked by this user
{% endif %}
{% endif %}
{% if not user == profile.user %}
{% if not user|isblockedby:profile.user %}
{% if not profile.user|isblockedby:user %}
{% if not user|isfriendswith:profile.user %}
{% if profile.user|isfriendshiprequest:user %}
Accept Friendship Request
Accept Request
Decline Request
Block User
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Hope this helps.
This guide should be a good start:
http://docs.djangoproject.com/en/dev/ref/templates/
Let's analyze the code a little bit:
Friendship.objects would return the default manager on Friendship model. At this point you probably want to call one of the methods that return an iterator on this manager. For example the following template code iterates over all Friendship's:
{% for friendship in Friendship.objects.all %}
But this doesn't make a lot of sense. You probably want to iterate over Friendships for a particular user. The following code iterates over friends of the active user:
{% for friendship in user.friendship.friends.all %}
{{ friendship.user.username }}
{% endfor %}
The code above may not work. I can't remember why. But there is already a tag that gives you friends of a specific user:
{% load friends_tags %}
{% friends_of user %}
{% for friend in friends %}
{{ friend.username }}
{% endfor %}
Rant Section
It seems the app is not usable without reading the source. This is not good at all. The author of this app should have written better documentation. I should allocate some time to work on these issues sometime.
Related
I need to customize the shipping confirmation email. I want to use a tag to determine which of two text sections are included in the email. The problem is there is usually an array of tags. I can get section "A" like this...
{% for tag in tags %}
{% if tag == 'a' %}
A
{% endif %}
{% endfor %}
There is only a single 'a' tag in the array so I only get the "A" text once.
But I can't figure out how to get the "B" text to appear just one time.
If I do this, it appears for every tag that does not == 'a'...
{% for tag in tags %}
{% unless tag contains 'a' %}
B
{% endunless %}
{% endfor %}
Is there a way to get one instance of "B"?
You could repeat the same logic you did for A:
{% for tag in tags %}
{% if tag == 'a' %}
A
{% endif %}
{% if tag == 'b' %}
B
{% endif %}
{% endfor %}
Alternatively you could do a switch/case statement, I'd prefer this approach because it's easy to read, and if sometime in the future you would like to add another condition (tag), it would be easy and the code would still keep its elegance.
{% for tag in tags %}
{% case tag %}
{% when 'a' %}
A
{% when 'b' %}
B
{% when 'c' %}
C
{% endcase %}
{% endfor %}
If you have many tags it can become tricky, but if it's just two tags this is the general idea.
{% assign a_not_found = true %}
{% for tag in tags %}
{% if tag == 'a' %}
...
{% assign a_not_found = false %}
{% endif %}
{% endfor %}
{% if a_not_found %}
{... show b... }
{% endif %}
Otherwise
{% if tags contains 'a' %}
{...show a...%}
{% else %}
{...show b...%}
{% endif %}
I want to display "wholesale" collection link on top menu if customer is login otherwise i do not want to display "wholesale" collection link.
I followed following link instruction but it is not working for desktop menu
https://www.envision.io/blogs/ecommerce-pulse/80312001-how-to-add-a-wholesale-area-to-your-shopify-store-without-an-app
and added bellow code in mobile menu "header.liquid" file
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% for link in linklists[menu_handle].links %}
but when i try to put same code for desktop it is not working i am replacing above code with following code
{% include 'site-nav', linklist: section.settings.main_linklist %}
but it is not working after put following code for desktop nothing display on header before login and after login.
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% for link in linklists[menu_handle].links %}
Thanks
I think you need to try something like this.
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% include 'site-nav', linklist: menu_handle %}
I am new To Shopify ! i am trying to something like,i want to check that,the ID which i put on Textbox is in array or not !
here is my Product.Liquid
{% if settings.make_an_offer %}
{% for id in product.id %}
{% include 'pricewaiter' %}
{% endfor %}
{% endif %}
in above code,i need to check that settings.make_an_offer is in this array product.id or not..
make_an_offer this is an ID of my Textbox
so how can i do this?
any help please?
Place it like this :
{% for id in product.id %}
{% if settings.make_an_offer === id %}
{% include 'pricewaiter' %}
{% endif %}
{% endfor %}
I'm in a situation where hiding a certain vendors products in the control panel isn't an options due to an outside POS. For a test in search.liquid, I used search.terms like below. This code works but not everyone will type thevendor exactly the same way and will see the products if they don't type thevendor.
{% for item in search.results %}
{% if search.terms == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
I tried to figure out how to write the code to hide these products in a better way. I tried product.vendor like below but when I search for those products individually they are not hidden. The code:
{% for item in search.results %}
{% if product.vendor == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
Can someone tell me what I'm missing here? It seems it doesn't know what product.vendor is but when I print out who the vendor is, it displays the vendor. I don't understand why it's not hiding the products that are associated with this vendor.
{% for item in search.results %}
{% if item.product.vendor == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
This should work.
i want to do something like this in Shopify:
{% for i in (0..10) %}
{% capture slide %}slide{{i}}{% endcapture %}
{{ settings.slide }}//i need the value of this one
// i want to get the values for settings.slide1, settings.slide2 etc
{% endfor %}
Another example:
{% for i in (0..10) %}
{{ settings.slide[i] }}//i need the value of this one
{% endfor %}
This is a simplified version of what im trying to achieve.
Thanks
Try this:
{% for i in (0..10) %}
{% assign current_slide = 'slide' | append: i %}
{{ settings[current_slide] }}
{% endfor %}