Search

Is there anyway of assigning and formatting a hidden date field to be associated with the $label/asap in my page template?

Here is what I have so far:

<xsl:value-of select="$labels/closing-date"/>: 
<xsl:choose>
<xsl:when test="asap != 'Yes'">
    <xsl:call-template name="format-date">
    <xsl:with-param name="date" select="to-date"/>
    <xsl:with-param name="format">d/n/Y</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
    <xsl:value-of select="$labels/asap"/>
        <xsl:call-template name="format-date">
        <xsl:with-param name="date" select="{$today}"/></xsl:with-param>
</xsl:otherwise>
</xsl:choose>

What I am after is a way of assigning today’s date to the asap label.. can anybody tell me if the above looks right?

Can’t test it right now as the site is live and wanna do it later in the evening!

You might want to remove the { } and you want to close out your </xsl:call-template>

It should be…

<xsl:call-template name="format-date">
        <xsl:with-param name="date" select="$today"/>
</xsl:call-template>

Try that.

Why remove the {} what is the difference?

And I get the fact that the xsl:template-call.. I have it ending earlier than I need it too.

cheers.. I’ll check it after lunch!

Also, does this mean that the value of $today is taken from the server date? or Do I have to have a value called $today and populate it with a new date everyday?

The ‘{}’ are only used with attribute value templates, where you are referring to a param/variable from within your output markup. I don’t think it is in the standard to accept them elsewhere, so for no other reason, it might throw an error.

the $today param is pulled from the server. It is one of a set of parameters that Symphony adds to to the XSL transformation for any Page that you are processing. You can see all of these using the debug tool by going to example.com?debug , then clicking the ‘Params’ link at right.

Some of these params are hardcoded, and are always available, but you can also create them from Data Sources (while editing a data source in Admin, it is called “Parameter Output” under Output Options). Any param pulled from a datasource has a ‘ds-’ prefix. You can also add a url parameter by adding it to the url string:

example.com?foo=bar

Would add a param to the transformation that would look like $url-foo = ‘bar’.

All of these together is referred to as the ‘param pool’. You can use any of these to filter your data sources.

What I am looking at doing here is giving the client the option of how to display jobs..

Either a “to-date” and “from-date” field for the job to appear live on the site

or a (from-date field which is checked to populate todays date by default when it’s created) and if there is no end-date field created.. we use the “asap” check box so a value of yes would result in the choose->when-> code being used to display the value of “asap”.

So code above is a means to allow the asap jobs.. to appear first when sorting by End Date along with the jobs that actually have an end date. hence the $today param needing to be dynamic for each day.

Does this make sense and do you think it could work.

Got it working in the end, thanks to you ashooner.. the removal of the {} did the trick! nice one

Anyway of assigning the server value of {$today} to a checkbox in the admin panel?

Would be really useful if a certain checkbox output the current date everytime it was retreived from the server.

I don’t really understand what you’re asking here…

You could do this in pure xslt, using if tags.

(if the checkbox is set, set a variable to $today, if it isn’t set, set the value to the date field, or something)

Ok, so I have a section with entries and I want to diplay them from a certain date -> to a certain date. The DS has the (later than or equal to {$today}) XPATH and the (earler than or equal to {$today}) filters to ensure I am only showing entries between these date ranges.. but I was looking for a way of having a checkbox to override the ending date so that it would display the entry until I manually deleted or changed it!

creativedutchmen I have used the if else tags and declared a variable of {$today} to the checkbox.. problem is.. it seems I need to assign a date in the future as well otherwise the entry will not show. Is there a way of having the checkbox override the end date field/take it’s place.. anyway of putting an XPATH on a checkbox filter maybe?

not sure if it’s possible, not sure if what I am after is even logical :(

If I understand correctly you want a Data Source with two filters:

  • where your Date field is between X and Y
  • OR where the checkbox is ticked

Unfortunately Symphony doesn’t allow for this, since adding two filters together will combine to an AND (i.e. between the dates X and Y and where the checkbox is ticked).

The alternative is to think about it the other way round. You could set the date filter to be “later than or equal to {$today}” as you have, but remove the upper filter. You can then filter in your XSLT to show entries only when:

  • the checkbox is ticked
  • OR the dates is earlier than Y

Obviously this won’t allow you to paginate, and might make for a heavy Data Source if you have many entries.

Another alternative is to try SymQL which might be able to provide this “OR” filtering that you need. I’m not sure about how you’re doing your date filtering so my example might be wrong, but something like this:

<?
require_once(EXTENSIONS . '/symql/lib/class.symql.php');
$query = new SymQLQuery('jobs-by-date');
$query
    ->select('title, description, date')
    ->from('jobs')
    ->where('start-date', 'later than {$today}')
    ->where('end-date', 'earlier than 2020-01-01', SymQL::DS_FILTER_OR)
    ->where('show-until-further-notice', 'yes', SymQL::DS_FILTER_OR)
    ->orderby('system:date', 'desc')
    ->perPage(10)
    ->page(1);

// run it! by default an XMLElement is returned
$result = SymQL::run($query);
?>

This should get entries where start-date is later than today, and either end-date is before 2020-01-01 OR a show-until-further-notice is checked.

Nickdunn, that’s a nice solution! I think the SymQL would be best suited as I still need the upper limit on some of the entries! i.e an end date so that the entry does not show past a certain date.. and then the checkbox is used if the client wants the entry to continue until further notice and they would not need to fill in a random date far into the future on the ‘end-date’ field to ensure output.

What do you mean in the first solution about paginating entries not possible?

Well, if you removed the filters and did this all in XSLT (rather than filtering entries in the DS) then the pagination information in your DS would be useless to you.

How about another solution — three date fields:

  • Visible Start Start
  • Visible End Date
  • System End Date

The first two are what you have already. The last is not a checkbox, but a Date field. Tell your client to enter either the same date into both End Date fields (for normal behaviour), or a date farther into the future into System End Date to allow jobs to appear for longer.

You then filter on Visible Start Date and System End Date. Visible End Date is purely for display purposes.

Well, if you removed the filters and did this all in XSLT (rather than filtering entries in the DS) then the pagination information in your DS would be useless to you.

Got it!

I’m liking the SymQL way best if it could work.. SYMQL work on 2.0.6? Reason being is that altering the workflow is not an option me thinks so a checkbox staying as a checkbox is better for client.. if only the value of the checkbox could be {$today} without using SymQl.. nevermind… my brain is thinking what ifs again! will see if I can have a play with this late ron. thanks again Nickdunn.

SYMQL work on 2.0.6?

Ah. Hmm. Nope. You’ll need to wait until 2.0.7 is stable and officially released before you can use SymQL. Apologies.

Das cool! Client: Deal with it :)

Nick,

As a work around could I do an if else in the template?

  1. Take out the XPATH in the to-date field from the DS filter
  2. put an if to-date == “”(nothing) and asap == “yes” to-date is 01-01-2020 (way into the futrue or something)
  3. elseif to-date != “” apply XPATH that was in the filter

Come to think of it, that would mean all entries are called rather than the XPATH filered entires.. hmmm

Come to think of it, that would mean all entries are called rather than the XPATH filered entires.. hmmm

Yes, hence my comment:

Well, if you removed the filters and did this all in XSLT (rather than filtering entries in the DS) then the pagination information in your DS would be useless to you.

It’d be a performance bottleneck.

It’d be a performance bottleneck.

Can’t be having that now can we :) thought as much. cheers

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