Twig - Long Text with more button - drupal

Working in a template in Drupal 8:
I have a (long) text - Variable and want to find the first occurrence of </p> and replace it with </p><div class="collapse" id="viewdetails">.
I also wan’t to find the last occurrence </p> and replace it with </p></div><p><button data-target="#viewdetails" data-toggle="collapse">More.. »</button></p>.
The idea is to trim a long text and add a more button.
Is this possible with Twig?
Thank's a lot

Related

How to add <br> in mail section of WordPress CF7

I'm trying to get line breaks to properly display in the e-mails that the CF7 plugin generates. I am basically trying to dynamically generate a list of items to send through mail, based on what the user checks off on the front end. I am storing that list as a text string with <br> tags in a CF7 hidden input.
So, for example, the idea is to get a string like the following into the hidden input, and then display line breaks in mail:
item 1 <br>
item 2 <br>
item 3 <br>
And so on...and then the hidden input becomes like this
<input type="hidden" val="item 1 <br> item 2 <br> item 3 <br>">
However, when I receive the e-mail, I just see the "<br>" tags in plain text, but I need that to actually be line breaks. I tried checking the option to display the email in HTML format within the plugin's mail settings.
You must check the "Use HTML content type" box below the Message Body field.
Alternatively, just start a new line without the <br> tag, that works in most instances.

Append text to an existing field that contains text

I am trying to add text into a field that already contains text without clearing the existing text. Append the text essentially
The 'input text' keyword clears the field before each iteration so is not a viable solution
Does anyone know of a way to do this?
Why don't you simply use Get Text to retrieve what the field contains already, assign it to a variable, then use input text to add whatever you want. i.e
${original_text}= Get Text Input_Field_Locator
Input Text Input_Field_Locator ${original_text}+${append_text}
I recommend to use javascript, by calling Execute Javascript keyword from Selenium2Library as the following:
Execute Javascript $("#inputfield").val($("#inputfield").val() + " some more text");

Revolving Slider with JSON

I want to create something like this: http://codepen.io/cassidoo/pen/MyaWzp. However, in this the number of cycles are set at 5. I want to read in data from a json. For example, if my json has a bunch of quotes, then inside the div I would have:
<div class="quote">{{ parsed['quotes'] }}</div>
The trouble I'm having is how to make it keep revolving without having a set number of revolutions. Basically my end goal is to have a continuously revolver which goes through all quotes and then repeats the revolution. I was wondering what changes I can make to the attached link to achieve this.
You need to use ng-repeat to loop through set of data available.it will act as a for loop. look at below example code.
<div ng-repeat="quotes in parsed['quotes']">
<div class="quote">{{ quotes }}</div>
</div>

Getting the text value of link when clicked a particular link in a page in adobe dtm rules

Using the source code below, I need to track text values of clicked links.
How can I track this and whether page load rule or event based rule is beneficiary for it?
How to code this using dtm?
<div class="afgfj">
<section class="asked-questions">
<div class="g-bp-row-gutter p-comp-spacinottom p-rb">
<h2 class="p-heading-02 p-component-title">
Frequently Asked Questions
</h2>
<dl class="p-faq-main p-accordion"
data-ctn="S9031/26">
<dt class="p-top-10 p-faq-chapter p-active">
<span class="p-top-10-global">Top-10 FAQs</span>
<span class="p-top-10-local">Top 10 FAQs</span>
</dt>
<dd class="p-top-10 p-faq-list p-active">
<ul class="p-bullets">
<li class="p-faq-item" data-lang="ENG">
<div class="p-magnific-popup-launcher" data-comp-id="magnificPopupLauncher"
data-type="iframe"
data-title="Frequently asked questions"
data-close-label="Back"
data-href="//www.org.com/cgi-bin/oleeview?view=aa12_view_body.html&dct=QAD&refnr=0073544&slg=ENG&scy=GB&ctn=S9031/26">
How long does it take to get?
</div>
</li>
<li class="p-faq-item" data-lang="ENG">
<div class="p-magnific-popup-launcher" data-comp-id="magnificPopupLauncher"
data-type="iframe"
data-title="Frequently asked questions"
data-close-label="Back"
data-href="//www.org.com/cgi-bin/oleeview?view=aa12_view_body.html&dct=QAD&refnr=0020591&slg=ENG&scy=GB&ctn=S9031/26">
Can I recharge the appliance?
</div>
</li>
This is a perfect time to use an Event Based Rule. You'll also need to create a data element to hold the text value.
The main obstacle that I can see from your code would be identifying the A tag correctly.
First the Data Element: in DTM Rules, within Data Elements click Create New Data Element.
Enter a name, specify the type (CSS Selector seems the most appropriate here) then within the CSS Selector Chain list state how to reach it. My guess is for your code it would be "div.p-magnific-popup-launcher a" but you would need to test this. You can tell by opening a Inspect Element (F12) in Chrome or similar debugging gadget. There's a good blog about doing this from Adobe here.
You should also specify which part of the A tag to save. From your question you I believe you need 'text' which would capture items like "How long does it take to get?"
Under Event Based Rules within DTM click Create New Rule.
When you're happy with the settings on this page click Save Data Element.
Populate your name, and category if applicable. The Event Type should already be set to 'click'.
Within Tag you then have to set how to find the A tag through CSS, similar to above.
That's the basics, but you'll also need to set Criteria (what pages this should fire on). Furthermore, under the Adobe Analytics section you should set whether a pageview is incremented or not, and which eVars, Props and Events are populated as a result of the click. This is also where you can use the value from your Data Element. Under Link Tracking, choose Custom Link. Within Link Name, enter a percent sign (%) and your data elements should appear. Use the name you specified earlier.
Note: you should match up your populated eVars and Events etc. with your settings under Report Suites in the Analytics interface.
I am assuming you are attempting to get the text of an <a> element when it is clicked on.
Such as in the one below, you would want to get "How long does it take to get?":
How long does it take to get?
To do this, create an event based rule with the event type "click", set the element tag to "a". (See image below)
Next you will want to configure the Adobe Analytics section of the rule.
You will set the Tracking to s.tl() ,since you do not want to create a pageview when someone clicks the link (the page they view should already do that).
Then set an eVar and/or Prop to %this.text%. This is DTM notation to grab the text of the element that triggered the rule to fire.
Finally, set an event to trigger on this rule.
See image below for the configuration
This should track when an <a> element is clicked and store the text in an eVar

Formatting Title element in XML Feed with HTML tags

I am using ASP.Net's inbuilt classes to create XML feeds for a website. Here's the code I have,
SyndicationFeed myFeed = new SyndicationFeed();
myFeed.Title = TextSyndicationContent.CreatePlaintextContent
("XYZ - In the first line <br/> in the second line");
When rendered it shows as it is -
XYZ - In the first line <br/> in the second line
whereas I want it
XYZ - In the first line
in the second line
I see that the behavior is only to myFeed.Title, whereas in myFeed.Description, I can use any HTML tags.
Any way to get HTML tags working with Titles?
Use the SyndicationContent.CreateHtmlContent Method instead. SyndicationContent.CreatePlaintextContent always escapes the text to make it render literally.

Resources