Search

Hi, gurus. I’ve created kind of gadgets on my symphony site. Say, i have several correspondent data sources: gadget-news, gadget-reviews, etc. How can one randomly choose amongst ‘em? I don’t want to create big fat xml with all possible data, but rather import only few of gadgets in a time within a page.

If you set your data source to sort by System ID and then Sort Order Random. Also set your output to about 5 or 10 and use the advice here. I’ve not tested it so not too sure how random it is though.

I’m sure Allen would know better ;)

I realise there’s reference to the umbraco library in the code. I’m just stepping out the door otherwise I’d tidy it up for you. Maybe when I get back…

Say, i have several correspondent data sources: gadget-news, gadget-reviews, etc

Are all your “gadgets” pulling from one section, or do you have a separate Section and Data Source for News, Review and so on? If it’s all in one section then as designermonkey said you can sort RANDOM and limit to one entry.

You’ll need to customise your PHP to do this. I would achieve it thus:

Create a new (custom) Data Source: “Gadget Type” which adds a param to the param pool ($ds-gadget-type). The value of this param will be a randomly selected string (your own random-generator logic) such as “review” or “news” or whatever.

Then customise your existing “Gadget News”, “Gadget Reviews”, “Gadget XYZ…” data sources by adding this param into the dependencies array:

$this->_dependencies = array('$ds-gadget-type');

Then inside the grab() function of each of these Data Sources you should inspect the $param_pool array, look for the ds-gadget-type key and see what value it has. If it does not match that Data Source, return nothing, otherwise let the rest of the code in the function run and process your Data Source.

(Oh, and if you customise a Data Source remember to change its allowEditorToParse to return false to prevent to re-saving the DS in Symphony thereby losing your customisations.)

Nick, thanks for the reply, but i’m tooo noobish to understand your advice with php-stuff. As for my gadgets, whey get data from various sources. What i wanted is implemented (if i remember the fact) in XSLT 2.0 (conditional imports) :-) (as u know i can’t use xsl:imports outside xsl:templates :( ) e.g. depending on $category selected i’d like to import only few of styles from the pool of available for the current page.

<xsl:template match="data">
    <xsl:choose>
        <xsl:when test="$category='tv'">
            <xsl:call-template name="tv" />
        </xsl:when>
        <xsl:when test="$category='releases'">
            <xsl:call-template name="releases" />
        </xsl:when>
        <xsl:when test="$category='experts'">
            <xsl:call-template name="experts" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="experts" />
        </xsl:otherwise>
    </xsl:choose>
    <div style="clear:both;"></div>
</xsl:template>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details