<p>You can wrap your HTML in a <code>{% set myString %}</code> block and use <code>myString</code> however you need too. </p>

<pre><code>{% set myString %}
{% set resultsNum = 0 %}
&lt;h3&gt;{{ block.location }}&lt;/h3&gt;
&lt;ul&gt;
{% set searchString = block.location %}
{% for entry in craft.entries.section('journal').find() %}
{% for block in entry.locations %}
    {% if block.type == "location" %}
    {% if block.location == searchString %}
        {% set resultsNum = resultsNum+1 %}
        &lt;li&gt;&lt;a href="{{ entry.url() }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% endif %}
{% endif %}
{% endfor %}
{% endfor %}
&lt;/ul&gt;
{% endset %}
</code></pre>

CC BY-SA 3.0
2015-04-24T23:15:08.710Z
Thank you so much. It's not entirely working for me yet. When I test out the string with {{ myString }} plainly on the page, it renders the same HTML. But passing it in the array, it goes awry. But when I copy the HTML from inspector and examine it, it contains some kind of hard enters? If that's a thing. What I see is couple of screen height empty pages and some spaces at the end. I just enclosed what I had with {% set infoWindowHTML %} and {% endset %} (so no copy/paste done) what could be causing these enters to be added? (Not talking about <br> just type enters of some sort) thanks again!
Kitsune
CC BY-SA 3.0
2015-04-25T01:06:51.483Z
Maybe try Twig's [escape](http://twig.sensiolabs.org/doc/filters/escape.html#escape) filter ('e' for short). {{ myString|e('html') }} (html is the default I believe).
Douglas McDonald
CC BY-SA 3.0
2015-04-25T08:23:50.450Z
Figured it out by using string  | replace({"\n":"<br>"})

Thanks!
Kitsune
CC BY-SA 3.0
2015-04-24T22:42:08.207Z
2015-04-24T22:42:08.207Z
Aaron Berkowitz
<p>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 turned the info i want in the bubble into a html result. All I need to do is alter this so that the twig commands create a string I can pass on in the function that will add the pin.</p>

<p>So I'm trying to create a string result from the code below, which has all the results in it.</p>

<p>Here's what I got (and this works to produce the HTML I want to put in the info window of the pin:</p>

<p>—</p>

<pre><code>{% set resultsNum = 0 %}

&lt;h3&gt;{{ block.location }}&lt;/h3&gt;
&lt;ul&gt;
{% set searchString = block.location %}
{% for entry in craft.entries.section('journal').find() %}
{% for block in entry.locations %}
    {% if block.type == "location" %}
        {% if block.location == searchString %}
            {% set resultsNum = resultsNum+1 %}
            &lt;li&gt;&lt;a href="{{ entry.url() }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        {% endif %}
    {% endif %}
{% endfor %}
{% endfor %}
&lt;/ul&gt;
</code></pre>

<p>—</p>

<p>The resulting string would go here (this code works already if i set my own string of html:</p>

<pre><code>    {% set marker = {
    lat: result.geometry.location.lat,
    lng: result.geometry.location.lng,
    content: infoHTML 
    } %}
</code></pre>

<p>Thanks in advance for any help!</p>

CC BY-SA 3.0
2015-04-24T21:07:14.290Z
Which variables are you using to create a string?
Aaron Berkowitz
CC BY-SA 3.0
2015-04-24T21:26:00.647Z
None yet, but this generates the HTML I need to put into a string, which will go (see 2nd code block in first post)
Kitsune
CC BY-SA 3.0
2015-04-24T21:41:44.727Z
So you need that entire HTML chuck as a string and not as rendered HTML?
Aaron Berkowitz
CC BY-SA 3.0
2015-04-24T22:01:30.413Z
Yes, exactly that!
Kitsune
<string>
Twig result/contents into string
# Twig result/contents into string

(Asked by: username_0 on 2015-04-24)

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 turned the info i want in the bubble into a html result. All I need to do is alter this so that the twig commands create a string I can pass on in the function that will add the pin.
So I'm trying to create a string result from the code below, which has all the results in it.
Here's what I got (and this works to produce the HTML I want to put in the info window of the pin:
—
{% set resultsNum = 0 %}

{{ block.location }}

{% set searchString = block.location %}
{% for entry in craft.entries.section('journal').find() %}
{% for block in entry.locations %}
    {% if block.type == "location" %}
        {% if block.location == searchString %}
            {% set resultsNum = resultsNum+1 %}
            {{ entry.title }}
        {% endif %}
    {% endif %}
{% endfor %}
{% endfor %}


—
The resulting string would go here (this code works already if i set my own string of html:
    {% set marker = {
    lat: result.geometry.location.lat,
    lng: result.geometry.location.lng,
    content: infoHTML 
    } %}

Thanks in advance for any help!

**Tags:** string

> **Comments:**
> **username_1**: Which variables are you using to create a string?  
> **username_0**: None yet, but this generates the HTML I need to put into a string, which will go (see 2nd code block in first post)  
> **username_1**: So you need that entire HTML chuck as a string and not as rendered HTML?  
> **username_0**: Yes, exactly that!  

---

## 1 answers

### Answer by username_1 on 2015-04-24. Score: 2 | Accepted answer

You can wrap your HTML in a {% set myString %} block and use myString however you need too. 
{% set myString %}
{% set resultsNum = 0 %}
{{ block.location }}

{% set searchString = block.location %}
{% for entry in craft.entries.section('journal').find() %}
{% for block in entry.locations %}
    {% if block.type == "location" %}
    {% if block.location == searchString %}
        {% set resultsNum = resultsNum+1 %}
        {{ entry.title }}
    {% endif %}
{% endif %}
{% endfor %}
{% endfor %}

{% endset %}

> **Comments:**
> **username_0**: Thank you so much. It's not entirely working for me yet. When I test out the string with {{ myString }} plainly on the page, it renders the same HTML. But passing it in the array, it goes awry. But when I copy the HTML from inspector and examine it, it contains some kind of hard enters? If that's a thing. What I see is couple of screen height empty pages and some spaces at the end. I just enclosed what I had with {% set infoWindowHTML %} and {% endset %} (so no copy/paste done) what could be causing these enters to be added? (Not talking about <br> just type enters of some sort) thanks again!  
> **username_2**: Maybe try Twig's [escape](http://twig.sensiolabs.org/doc/filters/escape.html#escape) filter ('e' for short). {{ myString|e('html') }} (html is the default I believe).  
> **username_0**: Figured it out by using string  | replace({"\n":"<br>"})  Thanks!  

---

