Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Last active December 16, 2015 06:39
Show Gist options
  • Save drmmr763/5393238 to your computer and use it in GitHub Desktop.
Save drmmr763/5393238 to your computer and use it in GitHub Desktop.
Example of how to use PHP functions in template.php in sobipro template
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:template match="/entry_details">
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<xsl:variable name="title"><xsl:value-of select="entry/name" /></xsl:variable>
<h1><xsl:value-of select="php:function('RanchBrokers::PrettyTitle', $title)" disable-output-escaping="yes"/></h1>
</xsl:template>
</xsl:stylesheet>
<?php
public static function PrettyTitle($txt)
{
$txt = explode (" ", $txt);
$first_word = "<em>" . $txt[0] . "</em>";
if (count($txt) > 0) {
unset($txt[0]);
$rest = "";
foreach ($txt as $word) {
$rest .= " " . $word;
}
$PrettyTitle = $first_word . $rest;
}
else {
$PrettyTitle = $first_word;
}
return $PrettyTitle;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment