Search

How could I limit number of rows that article displays on a page with listed articles?

Backend or frontend?

frontend

Ad frontend: By "rows" you mean 1) entries listed in the list, e.g. articles in list of articles? Or 2) some rows like lines of text, e.g. article's perex text.

As for 1: by enabling Pagination in backend properties of your datasource which returns the article list and setting there also the required page size, e.g. 3.

no, i need to limit 2) perex text

Try these two XSLT Utilities

Original - has demo in comments at top http://www.getsymphony.com/download/xslt-utilities/view/20036/

Advanced http://www.getsymphony.com/download/xslt-utilities/view/20816/

They let you choose how many words you want and they will preserve html

As a base, you can use xpath's substring function, like

<xsl:value-of select="substring(my-perex-text-node, 1, 120)"/>

returns first 120 characters. This might cut into a word, so you may want to handle it further.

OR, you can set a fixed height to your markup holding perex text and hide everything that overflows, so with css. This will make sure that you always get e.g. exactly 2 rows (as opposite to the former example and also no words cropped) and also within fluid layout. Though I don't know now if its an elegant solution or barbaric :) Point of view.

@jeffleeder you beat my comment with your solution but I appreciate that :)

ಠ_ಠ

so, I copy this utility to place with other utilities, but I don't know to what should I apply this:

<xsl:apply-templates select="path/to/your/body" mode="truncate"/>

to make it work properly.

you have to load it to the page template as well, like how the master.xsl is loaded at the top of a page template

well, i know that, and i did that;

  <xsl:import href="truncate.xsl"/> 

but what I don't get is how to apply it to actually shorten my articles on homepage.

Ok so where you are getting the copy with a value-of or copy-of you want to use the apply template instead. place your xpath expression from your value-of/copy-of into that.

@diomed trying to do this in xsl is really hard and never yield good results. Truncating text is hard, truncating html is even harder, even with full fledged programming language (C, Ruby, PHP, Javascript, .NET and so on)

If you use Markdown formatting, you could try to select only the first few p elements.

    <!-- Output the two first paragraphs -->
    <xsl:copy-of select="field-name/p[1] />
    <xsl:copy-of select="field-name/p[2] />

What I do most of the time is two have 2 fields in that section: One that contain the actual full text, the other, a shorter version.

I use this shorter version both as the summary in the list and in the meta description tag on the detail page.

With Symphony, you have the control over the sections data model. I would recommend you to adjust the model to fix your needs instead of trying to do voodoo with a fixed schema.

My 0,02$.

Also

Ok so where you are getting the copy with a value-of or copy-of you want to use the apply template instead. place your xpath expression from your value-of/copy-of into that.

What this means is that should replace the or with

As I already told you, you must learn XSLT and XPath in order to be able to customize your Symphony installation.

So, if I understood correctly you have 2 text areas, right? 1 for shorter version of article and 1 for longer.

That seems simple enough for me.

I don't understand the meaning of: Number of default rows

What does that option do then? I thought it shrinks article to desired number of rows.

(just to be clear, are 1st and 2nd part of your previous post connected or are they different solutions?)

1 for shorter version of article and 1 for longer.

Yes that's what I typically create in my sections.

they different solutions?

They are totally different. One tries to solve the problem with code (XSLT). The other one (and prefered one) changes the data model to fits your need.

"Number of default rows" is the number of rows in the textarea field. It sets the height of the field.

Number of default rows" is the number of rows in the textarea field

Totally. And it's only backend UI related. The data will never get truncated.

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