Jump to content
Sign in to follow this  
ChrisColeman

config.xml - custom variables ..

Recommended Posts

I find it very useful to be able to pass variables using XML -

eg. <name>value</name>

I would find it even more useful if I could pass an array () -

eg..

   

Quote

<name><subvalue>x</subvalue><subvalue>y</subvalue></name>

Is something like that possible ?

 

There is a work around something like ..
 

Quote

 

<name-subvalue_1>x</name-subvalue_1>

<name-subvalue_2>y</name-subvalue_2>

 

        But thats obviously difficult to handle in PHP or Smarty.

 

Thanks.

Share this post


Link to post
Share on other sites

Posted (edited)

Each skin folder has an associated 'config.xml' that is used to define the 'characteristics' of the skin.

In that 'config.xml' it is possible to pass custom variables to 'php or smarty', currently it is (I think) only possible to pass scalar custom variables therefore if one needs to pass a set of variables to a 'skin' it is necessary to use a lot of custom variables.

I was just wondering if there is a way to pass an array, or more explicitly to pass an XML string which could easily be converted to an array and then passed to 'SMARTY or a 'hook' as an array (associative or numeric)..

Chris.

eg.

I have a custom links section on a website, which is defined in the appropriate config.xml, and sure I can parse that in PHP to pass the required links to SMARTY -

Quote

<customLinks>+Welcome_a=default
  #/Our_Catalog.html+Our Catalog_a=catpage
  #/contact-us.html+Contact Us_a=contact
  #/index.php?_a=vieworder+Order Status_a=vieworder
  </customLinks>

But if my config.xml would allow me to pass something like the following, then I would not need to parse the XML, CUBECART/XML would do it for me whilst reading the config.xml -

Quote

 

<customLinks>

<link><vis>/Our_Catalog.html</vis><url>Our Catalog_a=catpage</url></link>

<link><vis>/contact-us.html</vis><url>Contact Us_a=contact</url></link>

<link><vis>/index.php?_a=vieworder</vis><url>Order Status_a=vieworder</url></link>

  </customLinks>

 

 

 

Edited by ChrisColeman
word error

Share this post


Link to post
Share on other sites

From working towards a solution - and there is one - I discerned there to be a problem. The issue has been posted in the Github.

One might argue that these custom links can be hard-coded in the templates. But I can foresee the case where the data may need to be massaged before populating a template variable.

Share this post


Link to post
Share on other sites

For now, you might try this:

Within the existing <custom> node, if there is one:

<custom>
  <myLinks>+Welcome_a=default
  #/Our_Catalog.html+Our Catalog_a=catpage
  #/contact-us.html+Contact Us_a=contact
  #/index.php?_a=vieworder+Order Status_a=vieworder
  </myLinks>
</custom>

Then, the skin template code might be something like:

{foreach '#'|explode:$SKIN_CUSTOM.myLinks as $myLinkPair}
 {foreach '+'|explode:$myLinkPair as $myLinkKeyVal}
  {$myLink[$myLinkKeyVal[0]] = $myLinkKeyVal[1]}
 {/foreach}
{/foreach}

<pre>{$myLink}</pre>

Ideally, you would break apart $custom['myLinks'] in CubeCart's GUI->_setSkin() function assigning it to your own template variable.

Note: I haven't actually tried the template code. And the relevant PHP code in _setSkin() is too limiting.

Share this post


Link to post
Share on other sites

Yes 'parsing' the custom variable in a SMARTY template (as you suggest) would be a way of avoiding unnecessary 'hooks'.

Especially if a similar construct was used more than once in CONFIG.XML, which is already the case for myself.

Although as you already concur the best solution is  -

Quote

Ideally, you would break apart $custom['myLinks'] in CubeCart's GUI->_setSkin() function assigning it to your own template variable.

Maybe that will happen in a future release ?

Thank You,

                     Chris.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...