If/Else Loops in Templates: Question

Ceri
Ceri
@adolygwr
5 years ago
370 posts
I want to put a small text area on this page :- https://americymru.net/americymru/documentation/adjectives , above the (endless) list of adjectives on the page. Can this be done by inserting the required content in the appropriate template with an if/else loop? I know this can be done in order to change the appearance of a module. Indeed I have already done this in the Doc mod. What I am wondering is this:- will this work for an individual url? Can I construct an if/else loop in the template which will put my text (graphics, links etc) on this url and this url alone?


--
Ceri Shaw - AmeriCymru

updated by @adolygwr: 11/20/19 12:21:46AM
michael
@michael
5 years ago
7,692 posts
Yes its possible.

The steps are:
* identify which template it is where you want to change stuff
* use the {debug} in there to see if you can location the variable that contains the value "adjectives". It will be a $_post variable because it comes from the url.

Then add something like this to the template:
{if($_post['whatever-value-you-found-from-debug'] == 'adjectives')}
 whatever you want to put just on that page goes here.
{/if}

Use the "Template name in Source" tool from developer tools to find the template you need.

Docs: "Template name in source"
https://www.jamroom.net/the-jamroom-network/documentation/modules/932/developer-tools#template-name-in-source

Docs: "{debug}"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1477/debug

If you get stuck we can help.
Ceri
Ceri
@adolygwr
5 years ago
370 posts
I am assuming that the template I need is the item_index.tpl in the Doc mod. How do I get debug to display as it does in your video? I added the code in several places in the template but nothing happened??


--
Ceri Shaw - AmeriCymru
michael
@michael
5 years ago
7,692 posts
No need to assume anything, use the "Template Name in Source" so you dont have to guess. Because nothing happened its most likely not the right template.
Ceri
Ceri
@adolygwr
5 years ago
370 posts
I must be missing something. I ran "Template Name in Source" and it appears that the template I'm after is item_index.tpl BUT just to be sure I put the code in a couple of other likely candidates as well with no result. Where on the template page does the code go? Or doesn't it matter?


--
Ceri Shaw - AmeriCymru

updated by @adolygwr: 08/14/19 06:47:26PM
michael
@michael
5 years ago
7,692 posts
"Template name in source" is not currently on. If it was I would be able to see what templates are being used on this page:

https://americymru.net/americymru/documentation/adjectives
source.jpg
source.jpg  •  835KB

Ceri
Ceri
@adolygwr
5 years ago
370 posts
Yeah I turned it off before I went to bed last night BUT it's on again now. Is it possible to identify the template in question?


--
Ceri Shaw - AmeriCymru
Ceri
Ceri
@adolygwr
5 years ago
370 posts
It looks like it should be item_index.tpl but when I add the debug code to that template nothing happens?


--
Ceri Shaw - AmeriCymru
douglas
@douglas
5 years ago
2,767 posts
Ceri:
It looks like it should be item_index.tpl but when I add the debug code to that template nothing happens?

If you are not running in developer mode, make sure to reset the cache after adding the debug code in the template.

Hope this helps!


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
michael
@michael
5 years ago
7,692 posts
Looks like item_category_index.tpl to me.
location.jpg
location.jpg  •  450KB

Ceri
Ceri
@adolygwr
5 years ago
370 posts
Many thanks....will try again and remember to run in dev mode this time :) On a side (but related) issue, I have realised that I can include a general note at the top of that page by simply adding a non alphabetic entry at the top of the list ( see:- https://americymru.net/americymru/documentation/adjectives ). BUT is there any way that I can introduce html into the title field? I would like (if poss) to put a few hr's around ANSODDEIRIAU CYMRAEG - WELSH ADJECTIVES FAQ


--
Ceri Shaw - AmeriCymru

updated by @adolygwr: 08/17/19 05:07:55PM
michael
@michael
5 years ago
7,692 posts
You could just use your IF/ELSE to put the title in there at the top, then you dont need to add in any html to the title.
Ceri
Ceri
@adolygwr
5 years ago
370 posts
That would be my preferred method. Will post later after my next attempt :)


--
Ceri Shaw - AmeriCymru
Ceri
Ceri
@adolygwr
5 years ago
370 posts
The only $_Post variable I can find in that template is this one:-

{$_post}
Array (6)
_uri => "/americymru/documentation/adjectives"
module_url => "americymru"
module => "jrDocs"
option => "adjectives"
_1 => "adjectives"
_profile_id => "42"

So I tried :-

{if($_post['/americymru/documentation/adjectives'] == 'adjectives')}
blah blah
{/if}


But nothing happened. On a side note it seems that I cannot remove the text 'learning about debug' even though I took the debug code out of the template?


--
Ceri Shaw - AmeriCymru
michael
@michael
5 years ago
7,692 posts
Almost right

Docs: "{debug}: Arrays"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1477/debug#arrays

try
{if $_post['option'] == 'adjectives'}
blah blah
{/if}
or
{if $_post['_1'] == 'adjectives'}
blah blah
{/if}
Ceri
Ceri
@adolygwr
5 years ago
370 posts
Great....many thanks :) Looking forward to playing with this :)


--
Ceri Shaw - AmeriCymru
douglas
@douglas
5 years ago
2,767 posts
You can also do it this way.

{if $_post.option == 'adjectives'}
blah blah
{/if}

or

{if $_post._1 == 'adjectives'}
blah blah
{/if}



--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos

updated by @douglas: 08/20/19 07:34:41AM
Ceri
Ceri
@adolygwr
5 years ago
370 posts
Got it!!!! :) Many thanks....it seems I misread Michael's post above and was in the wrong template. It was indeed item_category_index.tpl :)


--
Ceri Shaw - AmeriCymru