X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Using ListChild weights to reorder templates (https://forum.x-cart.com/showthread.php?t=75435)

plumstripe 06-15-2017 03:22 PM

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.

cflsystems 06-15-2017 06:10 PM

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

plumstripe 06-16-2017 11:29 AM

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?

cflsystems 06-16-2017 05:56 PM

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.

qualiteam 06-20-2017 01:56 AM

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!


All times are GMT -8. The time now is 04:42 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.