Support ⇒ Themes ⇒ Template Loops and Namespace Scoping ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexThemes

Template Loops and Namespace Scoping Reply to topic


I'm trying to lopp through two different blocks, but I think I'm geting clobbered by the way the templating engine interprets namespace.

I'm iterating through rows,

<!-- BEGIN character_row -->

and then I iterate through a column array that just sets the column type, then the template branches based on that.

<!-- BEGIN character_column -->
<!-- IF character_row.character_column.S_COLTYPE eq 'a' -->

I'd like to then iterate through another array at the same level as character_column (e.g. "character_row.alt_list"), but I think the namespace is fixed in character_row.character_column. So if I ask to

<!-- BEGIN alt_list -->

it's looking for something of the structure "character_row.character_column.alt_list", which would be a sub array of a particular character_column element, which isn't what I want at all (the alt_list isn't really specific to a particular column, it should be able to appear anywhere in the template.

Is there any way to explicitly set the scope of the templating loop so I can do this? I looked at the source, and I didn't see any indication I could.

I also don't think I can do an "END" immediately after each IF branch, as I imagine the blocks are parsed in a way that wouldn't allow that.

Am I missing some critical aspect? I could just get rid of the column iterator and have users explicitly template the columns in the order and format they want, but I kind of wanted to offer some pre-rendered options that could be selected quickly, in any order, and just have it work.

It is pitch black. You are likely to be eaten by a grue.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Ubuntu 12.04, Atom D525/Apache 2.2.22/MySQL 5.5.38/PHP 5.3.10/Dragonfly 9.4.0.0 CVS


Try with two different "handle" files and then use <!-- INCLUDE filename --> inside the loop.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.6 / PHP 5.6 / DCVS


NanoCaiordo wrote
Try with two different "handle" files and then use <!-- INCLUDE filename --> inside the loop.


I'm not sure I understand the suggestion entirely, though I think it won't need to do what I need to do. I suspect it might at best give me a top-level namespace again, which would break me out of the row namespace I still require?

This is what each row looks like. Note that "character_alts" and "character_column" are at the same level and are children of "character_row":

[character_row] => Array ( [0] => Array ( [S_ROWCLASS] => row1 [S_GROUPHEADER] => [S_COLSPAN] => 12 [U_CHAR_PROFILE] => http://u.eq2wire.com/soe/character_detail/871881320992 [U_AVATAR_IMG] => modules/Roster_Master/images/avatars/archetypes/scout.png [S_AVATAR_WIDTH] => 50 [S_AVATAR_HEIGHT] => 50 [S_CHAR_USERNAME] => Tessil [S_CHAR_USERID] => 3 [U_CHAR_USERID] => Your_Account/profile=3.html [S_CHAR_TYPE] => Secondary [U_EDIT_CLAIM] => Roster_Master/rm=rm_edit_claim/characterId=2959904203.html [U_EDIT_CLAIM_IMG] => modules/Roster_Master/images/icon_edit.png [U_CLASS_IMG] => modules/Roster_Master/images/roster/classes/beastlord.png [U_RACE_IMG] => modules/Roster_Master/images/roster/races/kerran-male.png [U_RANK_IMG] => modules/Roster_Master/images/roster/ranks/rank-0.png [U_TRADESKILL_IMG] => modules/Roster_Master/images/roster/tradeskills/artisan.png [S_ALTLIST] => <br /><a href="http://u.eq2wire.com/soe/character_detail/871878789364" target="_blank">Tessil</a>, <a href="http://u.eq2wire.com/soe/character_detail/871878779446" target="_blank">Toukai</a>, <a href="http://u.eq2wire.com/soe/character_detail/871881320992" target="_blank">Catsby</a> [S_CHAR_PLAYEDTIME] => PT14H22M20S [S_CHAR_LAST_UPDATE] => Thu, 23 Feb 2012 10:34:31 [S_CHAR_PVP_WILD_KILLS] => 0 [S_CHAR_PVP_TITLE_RANK] => 0 [S_CHAR_PVP_KILL_STREAK] => 0 [S_CHAR_PVP_DEATHS] => 0 [S_CHAR_PVP_DEATH_STREAK] => 0 [S_CHAR_PVP_CITY_KILLS] => 0 [S_CHAR_2TS_AD_LEVEL] => 0 [S_CHAR_2TS_TINK_LEVEL] => 0 [S_CHAR_AA_SPENTPOINTS] => 0 [S_CHAR_AA_AVAILABLEPOINTS] => 0 [S_CHAR_STATISTICS_KILLS] => 387 [S_CHAR_STATISTICS_DEATHS] => 3 [S_CHAR_STATISTICS_MAX_MELEE_HIT] => 732 [S_CHAR_STATISTICS_MAX_MAGIC_HIT] => 500 [S_CHAR_STATISTICS_RARE_HARVESTS] => 11 [S_CHAR_STATISTICS_ITEMS_CRAFTED] => 3 [S_CHAR_TYPE_RACE] => Kerran [S_CHAR_ADV_LEVEL] => 24 [S_CHAR_TYPE_GENDER] => Male [S_CHAR_TYPE_DEITY] => None [S_CHAR_ADV_CLASS] => Beastlord [S_CHAR_TYPE_BIRTHDATE_UTC] => Wed, 07 Dec 2011 03:22:50 [S_CHAR_ART_CLASS] => Artisan [S_CHAR_ART_LEVEL] => 6 [S_CHAR_ACHIEVEMENTS_TOTAL_POINTS] => 0 [S_CHAR_ACHIEVEMENTS_TOTAL_COUNT] => 0 [S_CHAR_ACHIEVEMENTS_POINTS] => 0 [S_CHAR_ACHIEVEMENTS_COMPLETED] => 0 [S_CHAR_LOCATIONDATA_ZONENAME] => Butcherblock Mountains [S_CHAR_LOCATIONDATA_BINDZONE] => Frostfang Sea [S_CHAR_ARENA_CTF_DEATHS] => 0 [S_CHAR_ARENA_CTF_WINS] => 0 [S_CHAR_ARENA_CTF_TIMEPLAYED] => 0 [S_CHAR_ARENA_CTF_STREAK] => 0 [S_CHAR_ARENA_CTF_MATCHES] => 0 [S_CHAR_ARENA_CTF_LOSSES] => 0 [S_CHAR_ARENA_CTF_KILLS] => 0 [S_CHAR_ARENA_CTF_CAPTURES] => 0 [S_CHAR_ARENA_DEATHMATCH_DEATHS] => 0 [S_CHAR_ARENA_DEATHMATCH_WINS] => 0 [S_CHAR_ARENA_DEATHMATCH_TIMEPLAYED] => 0 [S_CHAR_ARENA_DEATHMATCH_STREAK] => 0 [S_CHAR_ARENA_DEATHMATCH_MATCHES] => 0 [S_CHAR_ARENA_DEATHMATCH_LOSSES] => 0 [S_CHAR_ARENA_DEATHMATCH_KILLS] => 0 [S_CHAR_ARENA_IDOL_DEATHS] => 0 [S_CHAR_ARENA_IDOL_WINS] => 0 [S_CHAR_ARENA_IDOL_TIMEPLAYED] => 0 [S_CHAR_ARENA_IDOL_STREAK] => 0 [S_CHAR_ARENA_IDOL_MATCHES] => 0 [S_CHAR_ARENA_IDOL_LOSSES] => 0 [S_CHAR_ARENA_IDOL_KILLS] => 0 [S_CHAR_ARENA_IDOL_DESTROYED] => 0 [S_ACCOUNT_AGE] => 50 minutes 21 seconds [S_ACCOUNT_LINK_ID] => 1424942177 [S_CHAR_GUILD_STATUS] => 0 [S_CHAR_GUILD_JOINED] => Wed, 07 Dec 2011 05:02:43 [S_CHAR_GUILD_RANK] => 0 [S_GUILD_RANKNAME] => Leader [S_CHAR_NAME_SUFFIX] => [S_CHAR_NAME_PREFIX] => [S_CHAR_NAME_LAST] => [S_CHAR_NAME_FIRST] => Catsby [S_CHAR_COLLECTIONS_COMPLETE] => 0 [S_CHAR_COLLECTIONS_ACTIVE] => 45 [S_CHAR_QUESTS_COMPLETE] => 95 [S_CHAR_QUESTS_ACTIVE] => 6 [character_alts] => Array ( [0] => Array ( [U_ALT_PROFILE] => http://u.eq2wire.com/soe/character_detail/871878789364 [S_ALT_NAME_LAST] => De'Mille [S_ALT_NAME_FIRST] => Tessil ) [1] => Array ( [U_ALT_PROFILE] => http://u.eq2wire.com/soe/character_detail/871878779446 [S_ALT_NAME_LAST] => [S_ALT_NAME_FIRST] => Toukai ) [2] => Array ( [U_ALT_PROFILE] => http://u.eq2wire.com/soe/character_detail/871881320992 [S_ALT_NAME_LAST] => [S_ALT_NAME_FIRST] => Catsby ) ) [character_column] => Array ( [0] => Array ( [S_COLTYPE] => u ) [1] => Array ( [S_COLTYPE] => ct ) [2] => Array ( [S_COLTYPE] => a ) [3] => Array ( [S_COLTYPE] => n ) [4] => Array ( [S_COLTYPE] => gr ) [5] => Array ( [S_COLTYPE] => r ) [6] => Array ( [S_COLTYPE] => acl ) [7] => Array ( [S_COLTYPE] => tcl ) [8] => Array ( [S_COLTYPE] => 2tsa ) [9] => Array ( [S_COLTYPE] => 2tst ) [10] => Array ( [S_COLTYPE] => q ) [11] => Array ( [S_COLTYPE] => s ) ) )

This is what the snippet of the template should look like to do what I want:

<!-- BEGIN character_row --> [somestuff...] <!-- BEGIN character_column --> [somestuff...] <!-- ELSEIF character_row.character_column.S_COLTYPE eq 'n' --> <!-- IF (character_row.U_EDIT_CLAIM eq '') --> <td class="{character_row.S_ROWCLASS}" style="white-space:normal"> <!-- IF (character_row.U_CHAR_PROFILE ne '') --> <a href="{character_row.U_CHAR_PROFILE}"{S_TARGET}> <!-- ENDIF --> {character_row.S_CHAR_NAME_FIRST} <!-- IF (character_row.S_CHAR_NAME_LAST ne '') --> {character_row.S_CHAR_NAME_LAST} <!-- ENDIF --> <!-- IF (character_row.U_CHAR_PROFILE ne '') --> </a> <!-- ENDIF --> </td> <!-- ELSE --> <td class="{character_row.S_ROWCLASS}"> <table style="border-style:none" border="0" cellspacing="0" cellpadding="0" width="100%"> <tr style="vertical-align:middle"> <td style="text-align:left;white-space:normal"> <!-- IF (character_row.U_CHAR_PROFILE ne '') --> <a href="{character_row.U_CHAR_PROFILE}"{S_TARGET}> <!-- ENDIF --> {character_row.S_CHAR_NAME_FIRST} <!-- IF (character_row.S_CHAR_NAME_LAST ne '') --> {character_row.S_CHAR_NAME_LAST} <!-- ENDIF --> <!-- IF (character_row.U_CHAR_PROFILE ne '') --> </a> <!-- ENDIF --> <!-- IF (character_row.S_ACCOUNT_LINK_ID ne '0') --> <!-- BEGIN character_alts --> [Can't iterate here, because already in the "character_row.character_column" namespace, need to be in "character_row.character_alts" namespace] <!-- END character_alts --> <!-- ENDIF --> </td>

It's an odd situation. I want to be able to iterate in the template over "character_row.character_alts" from any element in the loop through "character_row.character_column" WITHOUT having to have a copy of character_alts in each element of "character_row.character_column". =/

One possibility I condsidered is seeing if I can copy a pointer into each element of "character_row.character_column" and access the list from there, but I'd probably have to abuse the object to point it back to itself, and that'd be kind of dodgy.

The other is just to copy "character_alts" into the column I currently have templated for it, but that makes the template less flexible.

What I really need is a "BEGIN ../character_alts", ya know?

It is pitch black. You are likely to be eaten by a grue.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Ubuntu 12.04, Atom D525/Apache 2.2.22/MySQL 5.5.38/PHP 5.3.10/Dragonfly 9.4.0.0 CVS


What i mean is:
$cpgtpl->assign_handle(chrts_alts, character_alts.html)


Copy the loop inside character_alts.html
<!-- BEGIN character_alts --> <!-- END character_alts -->


In the main file use <!-- INCLUDE character_alts.html -->

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.6 / PHP 5.6 / DCVS


Hrm, no joy, I'm afraid. Don't think the scope's right still. Thanks for the suggestion though!

I may have to go with one of my alternatives... =/

It is pitch black. You are likely to be eaten by a grue.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Ubuntu 12.04, Atom D525/Apache 2.2.22/MySQL 5.5.38/PHP 5.3.10/Dragonfly 9.4.0.0 CVS

Last edited by darkgrue on Sun Feb 26, 2012 6:53 am; edited 1 time in total


I see a END missing ... but have you tried <!-- BEGIN character_row.character_alts -->

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.6 / PHP 5.6 / DCVS


NanoCaiordo wrote
I see a END missing ...


Oh. True. It's there, I just abbreviated too much.

NanoCaiordo wrote
but have you tried <!-- BEGIN character_row.character_alts -->


Yeah, that didn't work either. I think it's not really possible to do what I have in mind. I can work around it using Javascript, which I'll probably have to do anyway, considering what style of tooltips I have in mind (I'd like to have clickable links in the tooltips).

If it's a project you really want to take on, I've attached the relevant templates and the file driving it. You can see the loop for the alts at 712-723 and the column type at 725-734.

From looking at the code, I don't think what I have will work. Both loops are siblings in the template variables, and if I'm reading it right, once you down downwards in the namespace, you have to work at that level or below, and you can't go up and access a sibling without exiting the loop. So I can iterate over alts, or columns, but not both at the same time.

In any case, the help is appreciated!
Attachment: roster_master.zip
Description
Filename roster_master.zip
Filesize 14.63 KiB
Downloaded 11 Time(s)
You are not allowed to view/download this attachment

It is pitch black. You are likely to be eaten by a grue.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Ubuntu 12.04, Atom D525/Apache 2.2.22/MySQL 5.5.38/PHP 5.3.10/Dragonfly 9.4.0.0 CVS

All times are UTC


Jump to: