Page 1 of 1

SOLVED: Pulling array of variables into separate content page

Posted: Mon Apr 12, 2010 6:41 pm
by appleyard
Most of the sites I've been building with CMSMS so far have been pretty simple/straightforward, but I had a question about using the "Extra Page Attribute" fields for something in a project I'm working on...

Basically, this site will have a group of pages in which each page represents a house for sale. There will be a small spot for an integrated Google Maps box, which I could do manually for each house with no problem. However, I'd also like to have a separate page with a larger map that plots out each house automatically using the coordinates from each individual page.

I was wondering if it's possible to use an "Extra Page Attribute" field for the Google Maps coordinates, and to pull that string from each house page to generate the larger map. Specifically I want to call all child pages from a particular parent (e.g. a section called "Houses"), check if they have a value for Extra Page Attribute 1, and plug that into {foreach} to plot the map coordinates with a link to the corresponding page. Does that make sense?

Any help you guys can provide would be appreciated! Thanks!

EDIT: Subject changed to reflect using content block variables instead of Extra Page Attribute fields.

Re: Pulling array of "Extra Page Attribute" fields into separate content page

Posted: Tue Apr 13, 2010 10:39 am
by sgtstevil
Try downloading CGSimpleSmarty from the Module Manager, and adding content-blocks to your page like so:
{content block="Google Maps Coordinates" assign="coords" wysiwyg="false" oneline="true"} and call it with {$coords} where you want to place it in the page.

Then go to Menu Manager. CGSimpleSmarty will let you access different content-blocks like so:

Code: Select all

<ul>
{foreach from=$nodelist item=node}
{$cgsimple->get_page_content($node->alias,'Google_Maps_Coordinates,'coords')}
<li>{$coords}</li>
{/foreach}
</ul>
Keep in mind that you have to call the variables as you originally assigned them on the page (Google Maps Coordinates in this case, NOT coords), but with spaces replaced by underscores.

This would create an unsorted list, change to however the params would be passed to Google Maps, or to a JavaScript or whatever :).

Then call this menu-template like {menu template="Coordinate List" start="2.1" number_of_levels="1" start_level="3"}, and presto!

Re: Pulling array of "Extra Page Attribute" fields into separate content page

Posted: Wed Apr 14, 2010 10:12 pm
by appleyard
This looks like it will work perfectly. I was confusing the Extra Page Attribute fields for the functionality that Content Blocks provide. (I was heretofore unaware of how to use them!) I'll let you know (and add 'SOLVED' to the subject) if/when I get the thing working. Thanks very much, sgtstevil!

Re: Pulling array of "Extra Page Attribute" fields into separate content page

Posted: Tue Apr 20, 2010 7:46 pm
by appleyard
Consider this SOLVED. Thanks again, sgtstevil! I did a few things differently from your suggestion, but the concept was the same. Content blocks + CGSimpleSmarty = extremely versatile tool!

Re: SOLVED: Pulling array of variables into separate content page

Posted: Tue Apr 20, 2010 8:55 pm
by sgtstevil
most welcome! :)