Truncate content to the first paragraph with Smarty - smarty

On an article website using smarty template, I need to truncate the main content to create teaser. I can truncate by char but first paragraph length is totally unknown from article to article.
I want something smarter that just show the first paragraph:
Content:
This is my first paragraph and I want to display this and only this.
This the rest of the content and it is very long with a lot of words...
Teaser:
This is my first paragraph and I want to display this and only this.

So is the text to truncate wiki syntax or html at this point? If it's wiki the you should be able to do a search for \n\n using strpos php function (add it to the smarty functions in the security control panel if it's not one of the allowed ones already). Then you can do a substr function on the text and add the "..." or whatever after it.
If it's html then a preg_replace would probably be the best approach - something like
{preg_replace('/^.*?<\/p>/mis','$1"',$content)}...
...might just work (untested, sorry ;)
HTH

Related

Laravel string limit with html tag shows less item than the actual number of items

I am using laravel and blade to loop over some blog items. I wanted to show blog with html tags and also with str_limit function.
When I try
{!!str_limit($blog->body, 450)!!}
It only shows 10 blogs or 11 out of 22. It should show all items.
If I use {{ str_limit($blog->body, 450) }} it shows all but without html tags I mean no effect of html tag.
str_limit has no knowledge of HTML tags, so using it on a string that contains HTML will often result in an unclosed tag that breaks the rest of the page.
As an example, an excerpt that ends in <a href="http://google.co because it got lopped off there means the rest of your page is part of the <a> tag until you accidentally output a " and a > again.
A couple options are available to you:
Strip the HTML tags. I know you wanted to preserve them, but this remains the easiest way of generating an excerpt.
Output the entire body, but give it max height and an overflow: hidden to hide the rest. This has bandwidth downsides, so if your posts are enormously long, it may not be the best approach.
Produce your own excerpts as a separate field. Manual work, but you're always in control that way.
Find/code a HTML-aware excerpt generator. I'm not aware of a good one I can recommend - it's a complicated problem. You could try generating a str_limited string and then running the results through Tidy, which can sort of fix invalid HTML.

How do I create a numbered paragraph list in Github-Flavored Markdown?

Reading through GitHub's help website, I've come across a very neat-looking procedure list.
From GitHub's Create A Repo Tutorial
I have read through GitHub's Markdown Tutorial as well as the Markdown Cheatsheet, but have not found any way to perfectly replicate this type of format.
The closest I have done so far was to basically put a blockquote after a number list entry:
1. > line 1
>
> line 2
2. > line 3
>
> line 4
And it looks similar, but, well, see for yourself:
Is this the closest I can get to GitHub's format?
Is there a proper Markdown syntax that I have missed?
If not, is there a way to achieve this in raw HTML?
If you look at the source of that page you can see that this is just a normal ordered list containing paragraphs:
<ol>
<li><p>In the upper-right corner of any page, click...
So to produce that HTML with markdown simply use the normal ordered list syntax:
1. First paragraph here.
2. Another paragraph here.
The particular appearance of that page is done by styling with CSS. It looks a little involved, using the ::before pseudo-element. If you want to replicate something similar have a look at the page with your browsers inspector to see the the styles. Experiment until you understand how it works and can create the effect you want.
If you are looking to create this effect on your own Github pages (e.g. a README) then I think you are out of luck, since you can’t control the CSS.

How can I stop Joomla from stripping HTML code from the Contact info?

I've only spent maybe 30 mins searching online for this, and couldn't come up with a decent answer.
But anyway, in Joomla there are normal input fields for the Contacts component, but there's a textarea for the Address.
This would make me assume you can enter multiple lines of address in there, and it would be displayed as separate lines... but it doesn't. Even if I enter line breaks, the output is rendered on one line.
So I try to enter <br> to separate, and upon saving, Joomla strips these tags out.
In the template, the output is being written simply by echoing $this->contact->address
Is there anyway, to explode this input and replace linebreaks with <br> marks?
UPDATE:
For now as a temporary measure I'm able to add HTML code into the database values, which saves and outputs on the front end.
On a separate note, I'm now looking to remove the Subject line from the contact form, without hacking the code. and by using overrides as much as possible. Can anyone help?
Have you tried the Sourcerer extension?
Your question is pretty old, but did you get a solution to this Lee?
To create line-breaks in Joomla, titles, text areas etc. Easiest way to do this is to use the ReReplace extension from NoNumber: http://extensions.joomla.org/extensions/edition/replace/4336
I personally use this to add line break in e.x. menu-item titles, where < br / > aren't allowed and get stripped.
With ReReplacer, you can create a custom tag e.x. {br} and then have ReReplacer replace {br} with < br / >.
So everytime you need to add a line break anywhere in Joomla, where html codes usually get stripped, you can just add {br} to have it add a new line.
Very old question but I've fallen into the same issue and tried to find a more user friendly solution.
You can enter multiple lines in the address textarea, and they are correctly outputted to the HTML page source. But as you know, newlines in HTML are not rendered, they have to be transformed to <br>.
For this PHP has a nice function, nl2br, that inserts a <br> each time it encounters a newline in a string.
So in html\com_contact\contact\default_address.php of your template, replace:
echo $this->contact->address;
with
echo nl2br($this->contact->address);
This would nicely do the job, and allow the user to naturally insert any newline in the contact address textarea that will be correctly rendered with the appropriate <br>; I believe this is quite more user friendly solution than your previous one of the user having to insert -br- tags in the address field.

How can I import a block of RTML into a yahoo merchant store?

I've put together a block of RTML that i would like to add to a product page. Now that i've got that, I'm trying to figure out how to place that whole block of RTML into the product's template. That may not be the right way to do it.
my desired result is that the html of the product page is rendered PLUS the html that would be rendered by my added block of RTML.'
What I have tried: as far as I can tell, i can only use the editor to add RTML 1 line / update at a time. which means anything complicated would take forever.
Yes Kristian, you're absolutely right. The operators in RTML take a very, very long time to insert because it requires a page refresh for each operator in the store editor. If you have a lot of HTML to update, you can use the RTML template uploader located here http://www.yourstorewizards.com/rtml-transfer-utility.html . While it is free to "download" templates, you are charged for "uploading" templates. This is because you aren't truly uploading or downloading templates. What the program does is move your mouse around the screen very quickly doing all the clicking for you.
At the very least, you can use the MULTI command to group other commands together. That way you can quickly duplicate operators/HTML. You can take a bunch of TEXT operators and quickly duplicate them inside a MULTI, and then duplicate the MULTI. This is probably one of the most efficient ways to do large blocks of HTML.
Another idea... Print out a script tag using a TEXT operator, and insert your HTML with JavaScript. Obviously you won't want to do this all the time, but if you're looking to insert a very large piece of HTML this may be your best bet.

What is the way to show small part of an article and make it open with read more link in codeigniter?

I am a newbie coder. I have learned a lot in the few weeks. Now I am making my blog site.
What I want is , show the limited part of 6 or 8 articles in the content div and make a read more link to show the article.
Can you tell me a way to do it?
Load the string helper and use the word_limiter, character_limiter (google for docs)
Or, contain a paragraph called "Summary" (varchar(255)) different to your main "Content" field (TEXT).
Initially load string helper and do as follows
word_limiter("data",limit);
You can check it here

Resources