I'm wondering if it is possible to easily mark up ERB templates using the Enmet/ZenCoding plugin for SublimeText2.
For example, you can normally do:
span.goodbye{hi there!} --> tab --> <span class="goodbye">hi there!</span>
Is there a way to do something like:
span.goodbye{<%= #post.content%>} --> tab --> <span class="goodbye"><%= #post.content %></span>
Actually, span.goodbye{<%= #post.content%>} works as required.
But I suggest you to create a custom snippet, something like "erb": "<%= |${child} %>" so you can write abbreviations like this:
span.goodbye>erb{#post.content}
Related
I have an Accordion Tab repeater that I would like to add an anchor tag to each unique title within the transformation.
Here is my code:
<li>
<a href="#tab-<%# DataItemIndex+1%>-<%# Container.Parent.Parent.ClientID %>" title="<%# Eval("Title") %>">
<span class="tab-item-title"><%# Eval("Title") %></span>
<span class="ui-icon"></span>
<%# String.IsNullOrEmpty(Eval<string>("MainText")) ? "" : "<div class=\"tab-item-subtitle\">" + Eval("MainText") + "</div>" %>
</a>
</li>
I tried adding:
<a id="<%# Eval("AnchorLinkName") %>" name="<%# Eval("AnchorLinkName") %>"></a>,
but it didnt work.
No need to post this in both the DevNet and SO. The DevNet automatically includes SO posts tagged as "kentico". Reference original answer here:
https://devnet.kentico.com/questions/adding-an-anchor-tag-in-a-repeater-transformation
Typically what you do in this case is have a datasource web part on the page and specify the necessary fields (where, page types, order by, etc.). You take note of the datasources name and add that to two repeaters on the page. One repeater is or your anchor link navigation and the other is the actual content you wish to display (link to).
One thing to note, is the anchor link needs to be a URL friendly value. So something with spaces or un-encoded URL values will NOT work.
In your navigation repeater (where you link FROM), you'll need something like the following in the transformation:
<li>
<%# Eval("DocumentName") %>
</li>
In your listing repeater (where you link TO), you'll need something like the following in the transformation:
<div class="faq-item" id="faq-<%# Eval("DocumentID") %>">
... your content here
</div>
Reference W3Schools Bookmarks
I'm working on my first Rails website, but I have a little problem: I want to display the <br/> tags as line breaks, but I also want to display the other tags as strings.
For example, the user input is:
<a href='#2'>Go to #2</a><br/><a href='#3'>Go to #3</a>
I want to display:
<a href='#2'>Go to #2</a><a href='#3'>Go to #3</a>
I know that I can display the <br/> tags as line breaks like this: <%= simple_format #user_input %>
But the problem is that this command display:
Go to #2Go to #3
And not:
<a href='#2'>Go to #2</a><a href='#3'>Go to #3</a>
Thank you in advance!
Use the Rails sanitize helper method and whitelist the tags you want to allow and leave those out that you don't. All those left out would be stripped and shown as text. So in your case it would be something like
<%= sanitize #user_input, tags: %w(br) %>
For the sanitize method api info see http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize.
You could do something like this:
<% #user_input.split("<br/>").each do |line| %>
<%= line %><br/>
<% end %>
Output:
<a href='#2'>Go to #2</a>
<a href='#3'>Go to #3</a>
Or even better, use a regexp so you can split either <br> or <br/>:
<% #user_input.split(/<br\/>|<br>/).each do |line| %>
<%= line %><br/>
<% end %>
UPDATE
Some cases will fail with the above approach, for example:
<input type="text" value="<br/>">
To be able to handle those cases, you could use Nokogiri, already bundled with rails, but you'll need add a couple of additional steps in your code.
First, your controller:
def some_action
input = "<a href='#2'>Go to #2</a><br/><a href='#3'>Go to #3</a><br><input type='text' value='<br/>'>"
#user_input = Nokogiri::HTML.parse(input)
#user_input.search('br').each { |br| br.replace("\n") }
end
Basically, you will create a Nokogiri HTML document and replace all br tags with "\n".
Second, create a css class to use those "\n" as break lines:
.new-lines {
white-space: pre-line
}
Now you will simply add this to your view:
<div class="new-lines">
<%= #user_input.css('body').children %>
<div>
Notice the use of class="new-lines", this is important to make each "\n" act as a <br>.
And the output:
Go to #2
Go to #3
<input type="text" value="<br/>">
Yes, there is a small caveat since the original value='<br>' turned into value="<br/>", but i hope that not to be a big issue; but if it is, then you could do something like this:
<%= #input.css('body').children.to_s.gsub("<", "<").gsub(">", ">") %>
And the output:
Go to #2
Go to #3
<input type="text" value="<br/>">
You may need to enhance this code further for more edge cases, but i think this example will do the trick.
Also consider using a helper instead of throwing all the code in your controller/view.
I have problem with Ruby on rails link effects.
My current code is:
<header class="navbar navbarfixed navbar-default navstyle>
<%= link_to "Cocktails",root_path, class:"btn btn-lg", id: "logo" %>
<nav class="cl-effect-5 container">
<span data-hover="new">new</span>
<span data-hover="test">test</span>
<span data-hover="test">test</span>
</nav>
</header>
So i need to convert the current html link style to ruby, so the effect is still there(cl-effect-5). I tried using this solution, but i get syntax error for some reason, even though i double checked everything...
One difference I noted with your code and the linked solution is that you have the hovers in the <span> versus in the <a> tag.
= link_to '#', data: { hover: 'test' } do
'Test'
I think that's what you may be looking for (not that the span is wrong per se). Also, make sure your application.css and application.js manifests are including bootstrap (or whatever front end UI kit you're using)!
I have been trying to find something about embedding HTML code inside a partial argument for days but I have not found anything so I'm guessing it isn't possible. But it seems like it should be.
I have a static page in my Rails app which has a lot of sections and each section can have subsections. I could just make the entire page just plain HTML. But I didn't want to repeat the same formatting over and over in case I want to change classes or something else.
So I have the following _section.html.erb partial file:
<div class="row">
<h4><%= heading %></h4>
<% subsections.each do |section| %>
<% if section[:header] %>
<h5 class="primary-text"><%= section[:header] %></h5>
<% end %>
<p><%= section[:body] %>
<% end %>
</div>
That works fine. But what if I want to include a link to a page or an email inside one of the subsections? It doesn't work just by passing it in as part of the quotes text. It shows the actual HTML tags.
Is there a real way to do this or should I give up and just write plain HTML with repeated section formatting?
You mark your text as html_safe. For example:
<%= section[:header].html_safe %>
But I would suggest using sanitize method because of security resonons:
<%= sanitize section[:header] %>
Probably sometimes you will want to configure sanitize method. Here you can read how to do this:
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html
You can read more about security here:
http://guides.rubyonrails.org/security.html#cross-site-scripting-xss
Rails noob here. I'm attempting to create create single-page scrolling site similar to this ...but, you know, not nearly as attractive :-)
Anyway, I've got my javascript working however I've developed much of the content (contact form, about us page etc etc) in different views which are hanging out in various html.erb files. Rather than cut and paste the contents of each into a single home.html.erb, I was wondering if there was a clean way to just embed the content from each view into my homepage view. Something like this:
<h1>My awesome homepage!</h1>
<div>
<div id="about">
<%= put_page_here page=about_us %>
</div>
<div id="our_product">
<%= put_page_here page=about_us %>
</div>
<div id="contact">
<%= put_page_here page=contact %>
</div>
</div>
If you would recommend going about this entirely differently, please let me know.
Many thanks in advance!
This should work:
<%= render partial:"shared/contact_us", locals:{variable:value} %>
Note that it will look for a view in app/views/shared/_contact_us.html.erb - notice the _ before the view. Pass the variables the view needs in through locals. More information on passing variables around here.