[SOLVED] Problem with spaces in a link

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
ColonelBlimp
Forum Members
Forum Members
Posts: 12
Joined: Fri Nov 06, 2015 5:06 am

[SOLVED] Problem with spaces in a link

Post by ColonelBlimp »

Hi,

Using 2.0.1.1, PHP 5.5.12

I have a problem with the link from a 'moreurl' for a news item. The front page of the site shows the summary with a link to 'Read more...' The link works okay, but the template name at the end of the link has non-escaped spaces.

Here is an example:

Code: Select all

https://thesite.org/news/6/1/Latest-news/d,News Detail.html
I would like to have the spaces at least translated to '%20' (without the quotes). Can anyone advise me as to what I am doing wrong?

The template code that is producing the summary is as follows:

Code: Select all

<article class="news">
  <h1>{$entry->title|cms_escape:htmlall}</h1>
{$entry->summary}
  <p>&nbsp;<a href="{$entry->moreurl|cms_escape:htmlall}" class="button">Read More...</a></p>
</article>
Many thanks
Last edited by ColonelBlimp on Fri Dec 11, 2015 1:20 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Problem with spaces in a link

Post by velden »

It's important to have a look at the {news ...} tag too. I assume you're using something like:

Code: Select all

{news detailtemplate="News Detail"}
Note that if you're using only one detail template AND make that template the default one, you can skip the detailtemplate parameter.

Code: Select all

{news}
This will generate urls without the template name in it.

If you still need to replace only the spaces: either give the template another name or use:

Code: Select all

{$entry->moreurl|replace:' ':'%20'}
ColonelBlimp
Forum Members
Forum Members
Posts: 12
Joined: Fri Nov 06, 2015 5:06 am

Re: Problem with spaces in a link

Post by ColonelBlimp »

Thanks for the reply.

You are correct about the {news} tag - it uses both the 'summarytemplate' and detailtemplate' parameters.

I'll try the 'replace' code. My fall back position is to rename the template without spaces, but that would make it inconsistent with the names of all the other templates.

Thanks again for the help. The site is up and running now: just tweaking things here and there.
Locked

Return to “CMSMS Core”