In SilverStripe 3, How can I put multiline comments in template file ?
single line comments can be done with <%-- my comment --%> (or the html way <!-- my comment --> which will be sent to the browser, but hidden not displayed.)
as far as I know, there is no multiline comment in silverstripe templates.
An ugly work around would be <% if false %>, like so:
<% if false %>
some
comment
text
here
<% end_if %>
Related
I'm new in phoenix. I need to display all the posts and pictures to them on the main page. I written below code in my index template:
<img src="<%= Blog.Image.url({#post.image, #post}, signed: true) %>">
And i got this
lib/blog_web/templates/post/index.html.heex:19:21: expected closing " for attribute value
What i missing?
The HEEx documentation notes:
...code interpolation using <%= ... %> and <% ... %> are restricted to the body (inner content) of the HTML/component nodes and it cannot be applied within tags.
Instead, there is specific HEEx syntax attribute={expression} for interpolating attribute values. In your example, you'd use
<img src={Blog.Image.url({#post.image, #post}, signed: true)}>
The engine will correctly insert quotation marks and other escaping as required (or, if Blog.Image.url/2 returns nil, omit the attribute entirely).
Is there a silent tag for groovy simpleTemplateEngine, if not perhaps another template engine?
What I am looking for is a tag which does not print a new line for if statements like <%- -%> for ERB in Ruby.
Take a look at the code below:
import groovy.text.*
def binding = ['Foo':'Bar']
def template = """
<% if(true){ %>
<%= Foo %>
<% } %>
"""
def rendered = new SimpleTemplateEngine(true).
createTemplate(template).
make(binding).
toString()
print rendered
Because it's running in debug mode it prints the source code for the parsed template, we can see that it's printing a new line before and after the desired output:
-- script source --
out.print("""
"""); if(true){ ;
out.print("""
${ Foo }
"""); } ;
out.print("""
""");
/* Generated by SimpleTemplateEngine */
-- script end --
I obviously already tried <%- -%> but I've got a syntax error :(
I have an application I want to use for my teaching studio where I create lessons that students can view. the lessons are specific to each student so they are linked via a :user_id (user has_many lessons, lesson belongs_to user). I can bring up specific lessons based on which user it is but the one part I cannot figure out is how to get a video (youtube) link to display correctly. What I want is to save the link along with the text for the lesson. The text and title and all that comes up fine right now, but the video will not display with embed code and throws a routing error in the iframe window.
Here is my code for the _lesson partial. "video_url" is the name of the column in the database.
_lesson.html.erb
<li>
<span class="content">
<%= lesson.title %><br />
<%= lesson.lesson_notes %>
<iframe width="490" height="275" src="<%= lesson.video_url %>" frameborder="0" allowfullscreen></iframe>
</span>
</li>
this is the code in my show view.
show.html.erb
<% if #user.lessons.any? %>
<h3> Lessons (<%= #user.lessons.count %>)</h3>
<ol class="lessons">
<%= render #lessons %>
</ol>
<%= will_paginate #lessons %>
<% end %>
the error I get is below
No route matches [GET] "/users/www.youtube.com/embed/CFF0mV24WCY"
I kind of understand what is happening, but not really. I guess I am unsure why it is looking for that route instead of just embedding the code and then displaying the video. It brings up all the other text and stuff from the lesson so that is working fine. Is there not an easy way just to display the link so it embeds the video along with it? I have searched quite a bit but everything I find just deals with embedding the code into the html which I can do, but this needs to change based on the user so has to be pulled out of the database along with the rest of the lesson info. Any help would be greatly appreciated.
src needs to know the protocol, so if you don't include http://, the explorer assumes that the given src is next to your actual path.
A shitty solution could be add the protocol with a raw string:
src="http://<%= lesson.video_url %>"
But a way better solution is adding a filter to check if the protocol is included when you save the field.
Ruby beginner developing for Rails 4.
I have a tag like:
<input type="hidden" name="URLholder" value=" ??? "/>
that I want to add my application root URL in the value attribute (instead of ???). How do I do that?
Note above that I need an input of type hidden
Thank you.
If you are using ERB templates:
# Remember to use double quotes for string interpolation
<%= text_field_tag 'URLholder', "#{root_url}" %>
For hidden input types, there is a FormTagHelper in Rails called hidden_field_tag,
# Remember to use double quotes for string interpolation
<%= hidden_field_tag 'URLholder', "#{root_url}" %>
Ref: http://apidock.com/rails/ActionView/Helpers/FormTagHelper/hidden_field_tag
Hope it works :)
I am pulling html email content from a database. The html contains strings like :
<%# include view="MirrorPage" %> and <%= stagingArea.techField.label %>
that I would like to remove before displaying.
I'm using Coldfusion 9 and jSoup to parse the html. jSoup worked great removing <script> content that was in the html.
<cfset emailHTML=jsoup.parse(detail["html"]) />
<cfset emailHTML.select("script").remove() />
I just unclear on how to select <% with jSoup since it isn't a true "tag".
Thanks,
Gary
When you use jSoup to parse HTML which contains <%# ... %> it gets converted to <%# ... %> and is treated as text.
Since it is simple text, there's no way for jSoup to pick it up, or treat it any different to other text.
Assuming these markers are placeholders/tokens that follow simple rules (i.e. there's no nesting, they wont contain '%' outside of their markers, etc), you can remove them with a regex like this:
<cfset emailHTML = rereplace( emailHTML.html() ,'<%[#=][^%]+%>','','all') />
(You may or not want to then use jsoup.parse(emailHTML) to get the string back into an object again.)
Of course, if these placeholders are there for a reason, you may need to do something more complex than simply removing them - and if they might be including HTML then you need to consider if they should be processed before jSoup is invoked to remove script tags/etc.