开发者

How to include template in all pages

i want to include design in all pages, for this i had set a master page layout, it works perfect.Then i want to add some portions to each page of my site,i am also done this by creating a utility page, but problem is repeats all contents. here is my code

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

<xsl:template match="/data">

    <h1><xsl:value-of select="$page-title"/></h1>
<ul><xsl:apply-templates select="/categories/entry"/></ul>

</xsl:template>
<xsl:template match="categories/entry">
        <div class="left_wrap">

            <div class="large_video"><img src="{$workspace}/images/video.jpg" style="border:#393939 solid 1px;" /></div>
            <div class="title1">Categories<img src="{$workspace}/image开发者_如何学编程s/arrow.jpg" /></div>
            <div style="float:left; width:680px;">

                <div class="category_block">
                <div class="category_title"><xsl:value-of select="title"/></div>
                <div class="category_image"><img src="{$workspace}/images/politics.jpg" /></div>
                <div class="category_info"><xsl:value-of select="description"/></div>
                <div class="date"><img src="{$workspace}/images/time.png"  style="float:left;"/><p style="float:left; width:120px; margin-left:6px;">2 days ago</p></div>
                </div><!--category_block END-->

            </div>            
         </div> 
</xsl:template>


</xsl:stylesheet>  

I want to repeat only the "class='category_block'" div ,but i need all other in this page. How is it possible in symphony?. Also i want to limit category description character count to 100 character in my home page, how can i limit it.


Firstly, is your <div class="left-wrap"> meant to be repeated for each category entry, or should it contain all categories? I'm going to assume the latter, as that seems to make most sense given what I'm seeing here.

If that's so, your data template should look like this:

<xsl:template match="data">
    <h1><xsl:value-of select="$page-title"/></h1>
    <xsl:apply-templates select="categories"/>
</xsl:template>

That will match the categories node and allow you to set up the container for all your category entries:

<xsl:template match="categories">
    <div class="left_wrap">
        <div class="large_video">
            <img src="{$workspace}/images/video.jpg" style="border:#393939 solid 1px;" />
        </div>
        <div class="title1">Categories<img src="{$workspace}/images/arrow.jpg" /></div>
        <div style="float:left; width:680px;">
            <ul>
                <!-- This will be your repeating block -->
                <xsl:apply-templates select="entry"/>
            <ul>
        </div>            
     </div> 
</xsl:template>

Now, when you've got more than one entry, whatever's in the entry template below will be repeated for each:

<xsl:template match="categories/entry">
    <li>
        <div class="category_block">
            <div class="category_title">
                <xsl:value-of select="title"/>
            </div>
            <div class="category_image">
                <img src="{$workspace}/images/politics.jpg" />
            </div>
            <div class="category_info">
                <xsl:value-of select="description"/>
            </div>
            <div class="date">
                <img src="{$workspace}/images/time.png"  style="float:left;"/>
                <p style="float:left; width:120px; margin-left:6px;">2 days ago</p>
            </div>
        </div><!--category_block END-->
    </li>
</xsl:template>

Obviously, I've had to make some assumptions here, so let me know if this isn't exactly what you're after. Also, bear in mind that with XSLT there's always more than one way to do something.

Finally, you should consider cleaning up your markup a bit. Lots of extraneous, non-semantic divs and so on. Your <div class="title1"> should probably be a heading, for instance. Ditto the <div class="category_title">.

To answer your last question about truncating the description, try this utility from the Symphony site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜