Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Using ListChild weights to reorder templates

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 06-15-2017, 03:22 PM
 
plumstripe plumstripe is offline
 

Member
  
Join Date: Sep 2016
Posts: 11
 

Default Using ListChild weights to reorder templates

I understand that changing the weight attribute of listChild changes the order of templates or file contents.
By this I mean a file with this in:
# @ListChild (list="body", weight="500")
places the contents of the file somewhere in the body code.

But although there are many posts that mention using ListChild weight, and giving different weight values, I can't see an explanation anywhere of how the weights actually work.

For instance, if I change the weight from 500 to 300, will that move something up or down in the ListChild list? ie does an item with a weight of 500 come before one with a weight of 300? or the other way round?

What value weight do I need to place a piece of code directly below the opening body tag? Or below a certain other template?

Can I use weights to move things up and down in the <head></head> section of the html by changing the weight in the following:
# @ListChild (list="head", weight="500")

I find X-cart documentation has many examples, but no clear documentation of how attributes such as 'weight' work, or say, a list of the values one might substitute for xxx in @ListChild (list="xxxx", weight="500")

If you just give people examples, without actually explaining what's going on, you're just giving your users a fish, and not teaching them how to fish - ie it's hard to know how to adapt the examples for another use.

Thanks.
__________________
5.3.1.3
Reply With Quote
  #2  
Old 06-15-2017, 06:10 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Using ListChild weights to reorder templates

The weight is integer. The higher the number the lower the item is in the list. Template with weight 100 will load before one with weight 200 and after one with weight 50. I suspect templates with same weight will load in the order the module or template is called or alphabetically, not sure. I have not tested but I assume you can have negative weight too.

template with @ListChild (list="body", weight="0") will load first in the list of templates but not necessarily right below the body tag. It depends if cart is loading something else first which does not depend on listchild
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
qualiteam (06-16-2017)
  #3  
Old 06-16-2017, 11:29 AM
 
plumstripe plumstripe is offline
 

Member
  
Join Date: Sep 2016
Posts: 11
 

Default Re: Using ListChild weights to reorder templates

Thanks for this - really helpful.
I'm just wondering if you can use the weight attribute to change placement of items in the head part of the html with
@ListChild (list="head", weight="xxx")

ie can I move things up and down in the head section by changing the weight value?
__________________
5.3.1.3
Reply With Quote
  #4  
Old 06-16-2017, 05:56 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Using ListChild weights to reorder templates

Yes I think so but again if something is loading in head section without list or with different list before the "head" list it will still load unchanged.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 06-20-2017, 01:56 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Using ListChild weights to reorder templates

Think of lists as of placeholders where templates and classes can add themselves into with the @ListChild directive.

List names doesn't match with HTML source tags directly. I.e. "body" and "head" are not the HTML tags, but just names.

For example, here is the skins/customer/header/body.twig template:
Code:
<head{% for k, v in this.getHeadAttributes() %} {{ k }}="{{ v }}"{% endfor %}> {{ widget_list('head') }} </head>
This template renders the "head" HTML tag and lets other templates and classes inject their code inside it by using @ListChild (list="head", weight="SOME_VALUE") declaration.

As Steve said, the higher the weight the lower the widget/template is in the list. So, to understand what weight you should specify for your template you are to search for other classes/templates using the same list name in their @ListChild directives and check their weights.

By adjusting the weigh you can move your templates/classes inside the list.

However, you must not edit source files of X-Cart or modules created by other developers. To move classes/templates that were created by other developers, you should create a custom module and use the methods like moveTemplatesInLists(). Here is a good tutorial on using these methods by Mike White:
http://xcartguru.com/knowledge-base/x-cart-5-kb/x-cart-5-moving-classes-and-templates-in-lists/


Hope this helps!
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:25 PM.

   

 
X-Cart forums © 2001-2020