Can I use $sys.pub_path in a velocity macro?

I’d like to distinguish to which environment I am publishing, to test something (we have a combined INT/PROD server that publishes to INT and then PROD).

I want to use an #if expression,

#if $sys.pub_path == INT_PATH then
try something new
#else
old way
#end

How do you reference $sys.pub_path in a macro in a template being built?

This link, http://forum.percussion.com/archive/index.php/t-11230.html, has a working fix. I don’t understand why he said it is not recommended.

I used this

#set ($siteID = $rx.asmhelper.getSingleParamValue($sys.params,“sys_siteid”))##
#set ($results = $rx.db.get(“RhythmyxData”,“SELECT root FROM RXSITES WHERE SITEID = ‘$siteID’”))
#foreach ($row in $results)
#set ($sitePubPath = $row.ROOT)
#end

Jeff,

In general Percussion will recommend against direct database schema references because if the underlying database schema changes between product versions, your code could break when you upgrade the product.

(Totally hypothetical scenario!) If an engineer changed the RXSITES table SITEID column to SITE_ID for something simple like a new database naming convention introduced by a new engineering manager, the below db lookup would fail after upgrade.

The reality is that we change the core schema very infrequently, particularly for central entities like Sites, so the risk of this happening is pretty low, however when implementing your sites with direct database calls, it is something to keep in mind.

DB lookups are also expensive operations at assembly time as it establishes a connection to the datasource, does a round trip to the database server, and returns the result, then releases the datasource, so if you can pull the value from an object (which are generally cached in memory by the system) you will get better overall template performance vs the direct db lookup.

Just wanted to explain where the “not recommended” was coming from. You can absolutely query the backend database directly, you just want to keep the above in mind.

-n

[QUOTE=Jeff Conrad;20816]This link, http://forum.percussion.com/archive/index.php/t-11230.html, has a working fix. I don’t understand why he said it is not recommended.

I used this

#set ($siteID = $rx.asmhelper.getSingleParamValue($sys.params,“sys_siteid”))##
#set ($results = $rx.db.get(“RhythmyxData”,“SELECT root FROM RXSITES WHERE SITEID = ‘$siteID’”))
#foreach ($row in $results)
#set ($sitePubPath = $row.ROOT)
#end[/QUOTE]