1

I want to truncate content text to be for example 1 line using sitecore sxa render variant

6

SXA uses Sitecore field renderers. By default, it is impossible to achieve something like that with out-of-the-box functionality.

However, there is one feature in SXA that let you do it:

  1. Add VariantTemplate item to your variant definition (/sitecore/templates/Foundation/Experience Accelerator/Rendering Variants/VariantTemplate)
  2. Define your template renderer and register it by adding new processor to getVelocityTemplateRenderers pipeline (see example processor AddTemplateRenderers, it registers: NumberTool and DateTool)
  3. Use your tool (fill Template field of an item created at first step)
<div class=introduction">
#set( $summary = $blogTool.GetSummary($item,"BlogIntroduction",200))
$summary
</div>

In the example above I have blogTool template renderer with a method GetSummary which accepts an item, field name, and a length to define how many characters from the field should be displayed as a blog summary. It is up to you what is your method signature.

useful links:

4

There are two ways to do it. 1 with code and other with CSS.

With CSS:

You can use the text-overflow:ellipis in your CSS for it.

div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

Reference: https://www.w3schools.com/cssref/css3_pr_text-overflow.asp

There is a bit difference between both.

  • With code, you only get the required number of text digits you enter.
  • With CSS, your Text will be there but ... will be there at the end.
  • The CSS solution is good for SEO practices.

With Code

The solution which @alan proposed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.