Search

hello,

For learning xslt I have to do this exercise.

Good, that was step 1, step 2, getting the values of $page from your cms and printing it out will be specific to that system so you will need to ask in a forum for that system.

within the xslt you need

<xsl:param name="page"/>

So my question is how do I get the value of the url page into the xslt stylesheet ?

Roelof

Did the forum escape some of your example code? I am not exactly sure what you are askin but…

In Symphony you can access various (types of) parameters

URL Parameters are the simple GET parameters that you can set/send through e.g. a form submission (with GET method) or through the url: e.g. <a href="/page?param=foo">link`

URL Parameters can be accessed in Symphony's templates by adding url-: e.g. <xsl:value-of select="$url-param"/> (This will output "foo")

Symphony also has some default parameters such as $current-page and $root (you can view all of them by adding ?debug to the end of the URL of your Symphony site's pages (make sure you're logged in).

Then there are Data Source output Parameters (e.g. $ds-my-articles) that are used internally for e.g. Datasource Chaining.

So, to answer your question. Try adding <xsl:value-of select="$url-page"/> to your template.

When you get a warning/error saying you are trying to access a parameter that is unknown, try adding it above your template as <xsl:param name="your-param"/> e.g. <xsl:param name="url-page"/> (note: no $!)

UPDATE Roelof, seeing your $page url makes it clear you are not talking about URL parameters. Adding <xsl:value-of select="$page"/> to your XSL template would show the $page parameter's value (if any)

Edited roelofs message so it actually showed the code. Please make sure your comments read properly after posting the.

Hah.. posting the... should that be them ? :)

Thanks, This xslt did the job.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    omit-xml-declaration="yes"
    encoding="UTF-8"
    indent="yes" />

<xsl:param name="page" />

<xsl:template match="/">
     <xsl:apply-templates select="/data/test/entry"/>
</xsl:template>

<xsl:template match="test/entry">
    <xsl:value-of select="$page" />
</xsl:template>

(I hope) this is obvious to you, but you do not need to put the <xsl:value-of select="$page" /> in that extra template matching /test/entry… The match is fine, but of little use if you do not actually do anything with the matched entry items.

You could just as well put the <xsl:value-of select="$page" /> in the first template (matching '/').

Try doing something useful with your matched entry items by e.g. displaying an id attribute <xsl:value-of select="@id" /> or a 'title' <xsl:value-of select="title" /> etc.

David, you mentioned the datasource output parameters above. How can I get access to them in a custom event. I can't find the "$ds-[data-source-name]" parameters when I dump everything inside Symphony::Engine()->Page(). Do you happen to know where those parameters are hiding?

Carlos, Events are run before any data-sources. So you would never have output parameters available up to my knowledge. Since data-sources some-times require data from events.

If you let us know what you are trying to achieve there might be other ways of doing it - such as using the ds-output when showing the form and passing the value through a hidden input field.

Thanks for the quick response gunglien. I have been able to access page params inside of events using Symphony::Engine()->Page(). In fact dumping Symphony::Engine()->Page()->param shows all of the page params except the ds-* ones. In any case, I was able to find those parameters-- they are private members --. I don't want to mess with Symphony's public/private accessibility (in order to maintain some semblance of security). That said, how would I go about doing what you described above? I've tried to get hidden fields to post, but so far no luck. Even something as simple as

doesn't seem to work. Dumping the $_POST shows all the other field values (that were explicitly set client side) but this item won't show up. Any tips?

Ultimately what I want to do is set a particular field value according to a static section in the back end. The static section is called "Approve by default". Every time a "Comment Entry" is made (from the front end) I want to set the "approved" of the "Comment Entry" value of "Approve by default". I actually tried using hidden fields before, but after being unable to receive the field's information server side, I gave up and tried going the route instead. Any help would be greatly appreciated. I've been scratching my head on this one for hours.

A hidden field should do the trick. Just make sure that it is within the same form that you are submitting.

Might be valuable if we know the value(s) of approve by default / approve. (select-box I presume) as you would have to set this to the value. Try setting this manually first say <input name='field[approved]' value='approved' type='hidden'/> see if that works. Once that works it must be the way that you insert the value via xslt. If that doesn't work probably you're passing the wrong value or inserted the input in the wrong place.

Gunglien thanks for your help. Here is my code, perhaps you can find my error:

<input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
  <!--<label for="author" class="inlined">Your name-->
  <div class="commenter-name comment-field">
  <input name="fields[name]" type="text" id="author" class="input-text short cn" size="22" tabindex="1"  placeholder="Your name"/>
  <!--</label>-->
  <!--<label>Email-->
  </div>
  <div class="commenter-email comment-field">
    <input name="fields[email]" type="email" class="input-text short" size="22" tabindex="2" placeholder= "Your email"/>
  <!--</label>-->
  <!--<label>Website-->
  </div>
  <div class="commenter-website comment-field">  
    <input name="fields[website]" type="text" id="url" class="input-text short" size="22" tabindex="3" placeholder="Your website (optional)"/>
  <!--</label>-->
  <!--<label>Comment-->
  </div>
  <div class="commenter-comment comment-field textarea">
    <textarea name="fields[comment]" class="input-text c" cols="58" rows="10" tabindex="4" placeholder="Your comment"></textarea>
  <!--</label>-->
  </div>
  </p>
  <div class="clearfix">
  <input name="fields[parent-blog-post]" type="hidden">
    <xsl:attribute name="value"><xsl:value-of select="data/individual-blog-entry/entry/@id"/></xsl:attribute>
  </input>

    **<input name="fields[approved]" type="hidden" value="yes"/>**  
  <button name="action[blog-comment-event]" type="submit" class="white" tabindex="5">Post Comment</button>

The bold snippet is the field I'm trying to set. Currently, this hidden field will not appear in the $_POST. I've attached a screenshot of the section in question. Is there something else I need to add (I hope its not a silly error I'm missing).

Correction the code in question did not get bolded. The snippet I was referring to is the second to last line right before the button.

Attachments:
field_screenshot.png

hmm - when you post your data. instead of checking the post. Can you try something else - as I am not sure if symphony removes these once read.

You should be able to see any event data in the debug xml. Change your form url - and add ?debug to it. This way you can see if there are any events launched. From there you can have an idea on why it is not saving.

The form looks good for me but the above might highlight any possible errors.

Gunglien, sorry for the late response. I don't know what I'd been doing wrong before but I tried simply using the hidden field and now its working. I'm probably going to lose sleep wondering what I did differently. In any case thanks for the help!

PS. does the symphony have a way to track which threads I've posted in previously? I'd lost track of where this thread was which is why I responded so late!

Glad it got to work finally :)

hmm unfortunately no - not really. What you can do is bookmark a discussion once you write in it, or would like to follow it. Otherwise you can only see all discussions or the ones you have created yourself.

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