Searching Within a String to Distinguish Groupings?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Searching Within a String to Distinguish Groupings?

Post by Squire4Hire »

I'm trying to find a practical way to flag Field Definitions to be placed in specific groups on a page based on how their alias is structured.

For example: gp1-city, gp1-style, gp1-location, etc would be parsed into a specific div section where gp2-size, gp2-information would be parsed into another.

Is there a means to search string values to determine whether or not to use the $item in a for loop?

(edit: or even a better way to go about doing something like this...)

Thanks.
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Searching Within a String to Distinguish Groupings?

Post by Jeff »

If you want a better way you need to give us more details of what you are doing (which module you are using).

For your question you could do something like:

Code: Select all

{if $variablename|substr:0:3 == 'gp1'}...{/if}
A guess at a better solution is to call the custom variables directly instead of using the default {foreach} loop. This will depend on which module is being used.

The general syntax will be something like:

Code: Select all

{$entry->custom_fields->fieldname->value}
You can use this to display the contents of the main var to see where things are in it (replace $entry with the name of the var)

Code: Select all

{$entry|debug_display}
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: Searching Within a String to Distinguish Groupings?

Post by Squire4Hire »

Thanks Jeff, that should get me what I need.

I'm working with LISE objects. I want to be able to choose which definitions are displayed in particular areas of the template. Iterating through the list using this method should allow me to do so.

If you have any suggestions on how to approach it in a more effective way, I'm all ears!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Searching Within a String to Distinguish Groupings?

Post by velden »

In my opinion iterating through the list is for sample templates (module developer doesn't know which field defs you're going to create).

In your case I'd suggest to create a custom template and use the specific field definitions directly like Jeff suggested.
So, skip the foreach loop for field definitions.
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: Searching Within a String to Distinguish Groupings?

Post by Squire4Hire »

I'm working with LISE Field Definitions. Ideally, I'd like to be able to pre-determine which section on the page the defs would go so I can reduce the amount of screwing around with templates in the event that new field definitions are introduced to the list item.

Using something like this with an if statement that parses the alias should allow me to do so - shouldn't it?

Code: Select all

{foreach from=$item->fielddefs item=fielddef}
		{if $fielddef.alias|substr:0:3 == 'gp1'}...{/if}
{/foreach}
Post Reply

Return to “The Lounge”