I want to write something like this in my Gatsbyjs Link tag:
<Link to=`/${this.props.latestPost.node.slug}`>Click Here</Link>
but it's not working, and my code looks like this:
Is there some way I could use a javascript expression inside the 'to' property? I want the slug to be dynamic, as the Link tag is for a 'recent posts' set of links, that will regularly update.
You need to escape it as Javascript:
<Link to={`/${this.props.latestPost.node.slug}`}>Click Here</Link>
Related
I am trying to use a javascript condition as a 'th:if' condition.
In specific i want to show a html element only when a scrollbar is existing in another element and tryed like this:
<div th:if="'javascript:document.getElementById(\'my-element\').scrollHeight>document.getElementById(\'my-element\').clientHeight'"></div>
Is something like this posible? Or should I do this in the '$(document).ready' function?
As #andrewjames rightly commented above, you cant embed evaluated JavaScript expressions into Thymeleaf. You might want to change your approach.
Try something like this to use javascript and thymeleaf together -
<script th:inline="javascript">
...
//your code
...
</script>
Read more about how to use thymeleaf and javascript together in official documentation -
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#javascript-inlining
Why is this happening?
HTML shows:
<meta content='http://www.costumingdiary.com/2015/05/freddie-mercury-robe-francaise.html' itemprop='mainEntityOfPage' itemscope='itemscope'/>
Structured Data Testing Tool output shows:
http://www.costumingdiary.com/2015/05/freddie-mercury-robe-francaise.html#__sid=md3
Update: It looks like it has to do with my breadcrumb list. But still, why is it happening, and is it wrong?
If the URL you want to provide is unique you can use the itemid property.
I was confronted with mainEntityOfPage by the tool after the latest update. And using Google's example I used the following code
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://blog.hompus.nl/2015/12/04/json-on-a-diet-how-to-shrink-your-dtos-part-2-skip-empty-collections/" />
And this show up correctly in the Structured Data Testing Tool results for my blog
I don’t know where the fragment #__sid=md3 is coming from, but as the SDTT had some quirks with BreadcrumbList in the past, it might also be a side effect of this.
But note that if you want to provide a URL as value for the mainEntityOfPage property, you must use a link element instead of a meta element:
<link itemprop="mainEntityOfPage" href="http://www.costumingdiary.com/2015/05/freddie-mercury-robe-francaise.html" />
(See examples for Microdata markup that creates an item value, instead of a URL value, for mainEntityOfPage.)
I have a URL from a third party site which should be the source of a script tag, something like this:
<script src="<%= #url %>"></script>
The above code shows a webform.
I would like to get the html code resulted by that code and store into a variable, something like this :
html_code = get_html('<script src="<%= #url %>"></script>')
Is that possible using Ruby/Rails (maybe using nokogiri) ?
If you're using jQuery in the browser and that code shows up in a well defined location, for example a <div> with a specific id then you can just grab it using your browser's JavaScript console:
$('#the_id').html()
That will show the raw HTML of that element presuming it dumps its content in an element with the ID the_id. You can use whatever CSS selector works.
Where that HTML goes in your document is impossible to tell from your example. A <script> can add any elements it wants anywhere in your document. You'll have to look around to see where it goes.
Load the page into a browser and then do View/Source in the browser. This will let you view the generated web page and you can find what URL was put into the <script> tag.
I have an video_link attribute.
When a User creates a Listing he can enter a Code (e.g. aabbcc).
I want to render this code inside my iframe link, like so
<iframe src="https://mywebsite.com/aabbcc/"></iframe>
So i tried
<iframe src="https://mywebsite.com/#{#vine.video_link}/"></iframe>
But this didn't work,
What am i doing wrong ?
I'm Getting no Error, but if i inspect the iframe on Page, the Interpolation is not rendering. im seeing just #{#vine.video_link}
Thank you
Oh! I get it... change it to:
<iframe src="https://mywebsite.com/<%= #vine.video_link %>/"></iframe>
You only need to do interp. like that if it's inside ruby code. In this case you're not escaping a string in ruby, you're just putting it in HTML (view).
Example.
If you were in a controller, let's say and had a string that looked like
variable = "<iframe src='https://mywebsite.com/#{#vine.video_link}/'></iframe>"
Edit to correct bad copy/paste job.
I'm working on a pastebin clone. I need the user to be able to type in HTML without it being used like HTML. For example, my user types "<html> Hello, world! </html>", and the html tags don't appear because the text is being treated like HTML. I do not want this to happen.
I want this to happen to this line:
<%=simple_format(#post.content )%>
How could I accomplish this? I tried using raw and .html_safe and they didn't work.
The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. These helper methods extend Action View making them callable within your template files.
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html