Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.


If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2015-11-25 01:06:38

Registered: 2015-01-20
Posts: 43

Re assign a value to an array variable - syntax

I am trying to change the page heading and the breadcrumb text on contactsheet.tpl  When I run debug there, I see there is an assigned template variable {$arrNavigationInfo} which is an array.  One of the elements of the array is called "title".  There is another element called "breadcrumbs" which is an array where the first element is "name".  This template variable is passed to an included file where I imagine the page heading and breadcrumb are displayed.  I thought it would be easy to simply change these elements and put in my own text.  I have tried various ways of assigning new values but nothing seems to work.  I have tried (amongst lots of others):
   {$arrNavigationInfo.$title = "My Page Title"}
   {assignarray var="arrNavigationInfo.title" value="My New Title"}
   {assign var="arrNavigationInfo.title" value="My New Title"}
These attempts are for the simpler of the 2 variables.  I was thinking that if one of the above worked I could do something like:
   {assign var="" value="My New Breadcrumb"}

Could someone please tell me the correct syntax for assigning a new value to an array variable.


#2 2015-11-25 13:19:40

Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Re assign a value to an array variable - syntax

I think you can do this with {append}. We added this as a modification to the base Smarty distribution for this very reason, although I think Smarty 3 now includes a version of this.

In any case, the syntax is:
{append var="arrFoo"  key="myKey" value="myValue" }

If you want to go a level deeper (for, you might need to assign the first level of the array to a temporary variable.
{assign var="tmpBreadcrumbs" value=$arrNavigationInfo.breadcrumbs}
{append var="tmpBreadcrumbs"  key="name" value="My New Breadcrumb" }

This /should/ work but please let me know how you get on.



#3 2015-11-25 20:35:15

Registered: 2015-01-20
Posts: 43

Re: Re assign a value to an array variable - syntax

Thanks Ben

The first piece works just great so I can change the page heading with:
    {append var="arrNavigationInfo"  key="title" value="xxx" }

However the breadcrumb is actually an array of arrays. But I took your first suggestions and worked it a bit.  I came up with the following which works, but will only work as long as there is the same simple breadcrumb list.  If the breadcrumb list changes this will break something.  This is good enough for what i need now and I may come back here in the future.
    {assign var="tmpBreadcrumbs" value=$arrNavigationInfo.breadcrumbs.0}
    {append var="tmpBreadcrumbs"  key="name" value="yyy" }
    {assignemptyarray var="myBreadcrumb"}
    {append var = "myBreadcrumb" key=0 value=$tmpBreadcrumbs}

    {append var="arrNavigationInfo"  key="breadcrumbs" value=$myBreadcrumb }

Last edited by mdyason (2015-11-25 20:36:17)


Board footer