• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Substitute spaces in string with hyphen

Explorer ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

I have 2 event names "Talk" and "Adele C Reserve which are the names of an event and displayed on the web site which are typed in by the client.

If i add the name of the event i wish to go to with "-"'s, it goes to the correct page and displays using the correct template

<div class="search-result">

    <h3>{{counter}}. <a href="/event-pricing/adele-c-reserve">{{name}}</a></h3>

    <p>{{description}}</p>

</div>

However the name keyed in by the client does not have the "-" so if i put in

<h3>{{counter}}. <a href="/event-pricing/{{name}}">{{name}}</a></h3>

This works for names that do not have any spaces "Talk" but if the name has spaces "Adele C reserve" it does not

I am trying to replace the spaces in the tag {{name}} with "-" with the following code. Not being that familiar with liquid and lack of information on BC on how to impliment liquid I am stuck.

<h3>{{counter}}. <a href="/event-pricing/{{'-" " will be replaced.' | replace: ' ', 'string' }}{{name}}">{{name}}</a></h3>

Can anyone point me in the right direction?

TOPICS
Developer

Views

357

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Dec 06, 2016 Dec 06, 2016

Thanks Liam

That does not quite work in this case as I need to use the Event list template and {{url}} uses the Event detail template. I have modified the booking module extensively with the help of BCGurus to give variable pricing.

I eventually got it to work with

<a href="/event-pricing/{{name | replace: ' ', '-' }}">{{name}}</a>

The event-pricing is a web app, in order for the path to work any name with spaces needed the space substituted with '-' and when I put in {{name}} alone I just had the s

...

Votes

Translate

Translate
LEGEND ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

Is this a webapp?

If it is you just use {{url}} and do not need to do any of that

If it is an event, events do not have an SEO friendly url and you would again use the event URL.

Just trying to get a grasp of the core thing your trying to do first to establish if you even need to do any of the above at all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

Thanks Liam

That does not quite work in this case as I need to use the Event list template and {{url}} uses the Event detail template. I have modified the booking module extensively with the help of BCGurus to give variable pricing.

I eventually got it to work with

<a href="/event-pricing/{{name | replace: ' ', '-' }}">{{name}}</a>

The event-pricing is a web app, in order for the path to work any name with spaces needed the space substituted with '-' and when I put in {{name}} alone I just had the spaces and no link. ie /event-pricing/Adele C option (not working) became /event-pricing/Adele-C-option (working).

Thanks for the response I have another issue I will use the {{url}} to fix

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

LATEST

Got you, Following those guides..

To much to go into and its what I get paid to build here but linking an event to a webapp is so much simpler to do and even more powerful then that lot know

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines