SMARTY "Namespacing" for custom fields

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
kendo451

SMARTY "Namespacing" for custom fields

Post by kendo451 »

Many of the modules permit custom fields.  Here is a way to convert your fieldnames into Smarty variables without creating conflicts with other template vars having the same variable name.

This example is from CGUserDirectory, but you can use the same technique for any of the modules with custom fields.

Code: Select all

{foreach from=$users item='oneuser'}
	{* properties *}
  	{foreach from=$oneuser.properties item='onepropvalue' key='propname'}
  		{assign var="ud_"|cat:$propname value=$onepropvalue}
	{/foreach}
What this did was concatenate "ud_" onto the beginning of each variable name.  You can use whatever prefix you want.

Example: If your custom field was named "alias" you can now call it with {$ud_alias}
Post Reply

Return to “Tips and Tricks”