Questions tagged [string]

String is a data type, which value is sequence of characters or symbols.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 views

How to control string translation through camel to kebab filters and back again (this is a tip not a question)

Putting this here in case anyone finds it useful. Strings like 'ABC thing' when pushed through camel and kebab filters can cause unexpected issues. For example… {% set str = 'ABC thing' %} {% set key =...
0 votes
1 answer
48 views

Accessing eager loaded Collections data

So I have a query to return series. At the same time I eager load the series client. {% set series = craft.entries() .section('series') .inArchive(false) .with('client') .collect() %} ...
1 vote
1 answer
71 views

Remove duplicate text from query results

I have written a query to select all categories for a certain entry. In this case, the category is called "Key Stage" and each one is written "Key Stage 1", "Key Stage 2" ...
  • 55
1 vote
1 answer
140 views

String interpolation in Redactor

I have a redactor field whose HTML contents contain links to other parts of the website. How do I render variables located in the HTML content of a Redactor field in Twig? Sample redactor content: &...
0 votes
1 answer
46 views

Replace quotes in an array

I'm trying to use a charting library within a Craft template. The chart expects an array of numbers that I'm building up from a table but I'm getting an array of strings instead. {% set donutData = [...
  • 1,835
2 votes
1 answer
185 views

How to display entries filtered from more than one category

I want to try to learn how I can filter entries by multiple categories. I realise similar questions have been asked in the past, but all the answers are for specific use cases. All I want to do is ...
  • 740
1 vote
1 answer
197 views

Append a string to the end of all rich text links

I'm trying to append a string to the end of all rich text links. Is there an already existing plugin for this?
  • 45
1 vote
1 answer
40 views

Normalizing Keywords Bug

The StringHelper::normalizeKeywords() doesn't work as I expected. When I normalize überblick it leads to the expected result: StringHelper::normalizeKeywords('überblick') -> ueberblick But when ...
  • 220
2 votes
1 answer
324 views

Twig result/contents into string

I'm trying to adjust a google maps so have pins that correspond with my posts. I'm nearly there but I'm trying to load info into the info window. I can set it's content already by hand. And I have ...
  • 333
6 votes
1 answer
1k views

Replace <p> with <p class="myClass">

Currently I am using twig's replace filter to replace the tags: {% set str = block.body | raw %} {{ str | replace('<p>', '<p class="myClass" data-wow-duration="1s">') }} But on output it'...
  • 441
8 votes
2 answers
2k views

How do I get model/record attributes in their proper types, and not just strings?

Here's my record (model is nearly identical): namespace Craft; class Recurly_PlanRecord extends BaseRecord { public function getTableName() { return 'recurly_plans'; } protected ...
  • 3,071
2 votes
2 answers
1k views

Remove white space and parenthsis from global from entry variable

I am using a phone number in a global variable called {{ global.phone }} with the format "(555) 555-5555". I'd like to use that same variable/string and remove spaces, dash, and parenthesis to use for ...
  • 287
6 votes
1 answer
565 views

Craft.log showing Buggy iconv installed. Will fallback to mbstring

I'm curious if others are seeing a similar error in their Craft logs. It says: Buggy iconv installed. Will fallback to mbstring. It's repeated over and over seemingly with almost every request. ...
2 votes
1 answer
61 views

Is there a prescribed way to to represent complex field types as strings?

I've found the need lately for a way to represent complex fieldtypes like Matrix, Entries, etc as strings. e.g. in the following plugins: https://github.com/boboldehampsink/auditlog https://github....
  • 3,071
10 votes
2 answers
6k views

How can I convert text into a URL-friendly string?

If I want to convert text into a URL friendly string for sharing text in a social media link, how would I go about that?
11 votes
1 answer
3k views

What's the difference between using single and double quotes in strings?

Is there a difference between using single-quoted and double-quoted strings?
  • 2,372
6 votes
2 answers
14k views

How can I incorporate a variable into a string?

How can I incorporate a variable into a string, so that the result is a longer string that includes the contents of a given variable? For example, I have a variable called apple and its value is "...
  • 2,372
7 votes
1 answer
24k views

How to replace characters in string

How do I replace ";" with "," in string "Red; Green; Blue"? {% set rgb = "Red; Green; Blue" %}
  • 2,372
5 votes
1 answer
14k views

Is it possible to convert string to uppercase?

Is it possible to convert a simple string ("Hello World!") to uppercase ("HELLO WORLD!")?
  • 2,372
4 votes
1 answer
364 views

What's that |t - filter for?

I found this part of code in the documentation {% set title = "Cocktail Recipes"|t %} What does |t mean there?
  • 2,372
5 votes
2 answers
6k views

How to check how many characters there are in my string?

Lets say I have a simple string: {% set string = "Simple String" %} How to get number of characters of my string?
  • 2,372
2 votes
1 answer
2k views

How can I convert a dropdown field value to an integer within a hash?

I'm setting up a twitter feed with craft.twitter.get() and I need to convert a dropdown value to an integer. Here is my code far: {% set cacheTime = sidebarBlock.twitterFeedCacheTime %} {% set tweets ...
  • 1,661