3 users online. Create an account or sign in to join them.Users
Unobtrusive templating
This is an open discussion with 12 replies, filed under General.
Search
Symphony uses XSLT for templating.
I'm not really following your question and could use an example to understand better. What do you want your partner to upload exactly? How would he modify it? What would you want the end result to be?
Sorry for the bad explanation.
I want to be able to upload an html template. It will have fake contents and images. Then I want to apply a XSLT to that template, mixing in the datasources to get the final result.
What I don't want is to have scattered fragments of HTML embedded in an XSL template. Is that possible?
It would be something similar to this, but using rules instead of just matching classnames
It would be something similar to this, but using rules instead of just matching classnames
Sure, don't see why it wouldn't be possible. You would need to build that layer/interaction though via XSLT.
@Codecaster, pure.js came as I didn't find something similar as XSLT for JSON. The classname matching is the automatic mode, and is ok for small templating. But there is mode with rules as well, using CSS selectors instead of XPATH to select nodes and transform them.
@tchvil sounds great, I might be using it in a rails project soon, but now I must use php because there is a client that doesn't want to change their hosting platform. So, what I am looking for is a framework or cms that provides declarative/pure templates. Now I am experimenting with Symphony and xsl:variable, importing a html document to use it as base template.
Anyone has any experience with this? My XSL knowledge is a bit rusty :D
Read through this thread:
I've been able to output the html using this:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="template" select="document('../templates/index.html')" />
<xsl:template match="/" mode="html">
<xsl:copy-of select="$template" />
</xsl:template>
</xsl:stylesheet>
but it's sloooooooow. the next step would be to apply more xsl templates to replace the boilerplate content with the real one, correct?
Thanks.
Why is it so slow? I tried using value-of instead of copy-of, and it takes ages to render the plain html in both cases (no datasource replacement yet).
Regarding slow speeds: Check the profiler by appending ?profile to your page URL.
To me your question sounds like you're trying to create a simplified templating language for your not-so-technical partner. That would be absolutely doable using XSLT (and Symphony later on). The fact that XSL-Stylesheets themselves are XML makes it perfect for this usecase: You can transform any XML to XSL-Stylesheets and evaluate those later on (like the eval() function in most programming languages).
The thing is though this definitely feels like a "precompiler step"; every time your partner changes the markup, he should then compile the XSLT templates from it (not using Symphony but on his local machine, using xsltproc) and put it in the Symphony installation. I wouldn't want this to be done "just in time" every time a page is served by Symphony.
I've created a small proof of concept in XSLT that roughly does the compilation:
Your partner creates a regular XML file containing all the HTML plus a few special attributes to do the flow control:
- Every time you want to invoke a loop you use the
datasource="name"attribute to point to the Data Source. - Inside the
datasourceelement you declare what each iteration should look like (basically like an anonymous callback function in Javascript) - Every time you want to output some data you use the
value="name"orcopy="name"attributes forvalue-ofandcopy-ofrespectively. You can fill those elements with dummy text, the dummy will be discarded.
The result looks like this, mostly clean XSLT.
Needless to say, you sacrifice a lot of flexibility XSLT provides but I guess the most used techniques should be realizable when using this workflow.
Is not a problem for me to provide a "bridge" XSL that iterates through the datasource in order to replace boilerplate contents in the HMTL for the real ones, so your approach isn't exactly what I am looking for. Thanks a lot though.
Create an account or sign in to comment.
Hi all,
I have just found Symphony and it looks great, I am eager to try it. But first I would like to know if there is a way to use plain markup as basis for templating. I mean, as a designer, my partner would like to upload his markup, full of Lorem Ipsum and placeholder images, you know. The idea then is to apply rules to transform that in a real page. He should then be able to even modify the "template", moving elements around, etc. Of course if some tags or attributes change, that might break the cms output, but that's another story.
Is that possible in Symphony? Any other CMS that can do that?
Thanks a lot in advance!