Site Tree

Working with Page Variables/Properties

Page variables (known as page properties in an earlier life) are very useful in setting up variables that can be inspected by templates at runtime. The inspected values can be then used to change the logic on a template. This allows developers to restrict the number of templates for a site, while maintaining the dynamic nature of ShadoCMS sites.

Here is a brief rundown on how you can programmatically work with page variables.

The ShadoCMS object for working with page variables/properties is: shadomx.core.pages.shado_obj_page_properties.

Adding a Page Variable

<!--- Instantiate the page properties object --->
<cfset oProps = application.shado_obj_factory.get("shadomx.core.pages.shado_obj_page_properties")>

<!--- Setup values for the property to be added --->
<cfscript>
stArgs = structNew();
stArgs.page_property = "MyTestProperty";
stArgs.page_property_value = "Value of the test property";
stArgs.page_uuid = request.sapi.site.getPage().uuid;
stArgs.lang = application.shado.languageService.getLanguageCode();
stArgs.date_created = now();
stArgs.last_updated = now();
</cfscript>

<!--- Add property --->
<cfset oProps.add(argumentCollection=stArgs)>

Getting All Variables for a Page

<!--- Instantiate the page properties object --->
<cfset oProps = application.shado_obj_factory.get("shadomx.core.pages.shado_obj_page_properties")>

<!--- Get all properties for a given page --->
<cfset qProps = oProps.getPageProperties(page_uuid=request.sapi.site.getPage().uuid)>

<cfdump var="#qProps#">

Getting a Page Variable by Name

<!--- Instantiate the page properties object --->
<cfset oProps = application.shado_obj_factory.get("shadomx.core.pages.shado_obj_page_properties")>

<!--- Setup values for the property to be retrieved --->
<cfscript>
stArgs = structNew();
stArgs.page_property = "MyTestProperty";
stArgs.page_uuid = request.sapi.site.getPage().uuid;
stArgs.lang = application.shado.languageService.getLanguageCode();
</cfscript>

<cfset qProp = oProps.getPropertyByName(argumentCollection=stArgs)>

<cfdump var="#qProp#">

Updating a Page Variable

<!--- Instantiate the page properties object --->
<cfset oProps = application.shado_obj_factory.get("shadomx.core.pages.shado_obj_page_properties")>

<cfset stUpdate = oProps.update(page_property_value="New Value for IndyTest",
andExprList="page_property = 'IndyTest' and page_uuid='#request.sapi.site.getPage().uuid#' and lang='#application.shado.languageService.getLanguageCode()#'")>



Comments

Add a comment

A note about languages and page properties/variables: it appears that if a property is not assigned a language, it will be displayed in the Variables tab under a separate heading "Shared Variables". (We ran into this when we created a tab for updating our custom properties).

# Posted by: Chris Simmons| 23 Nov 2008 | 03:48 PM

Add Comment