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).
Related
Rails 4.2
This asset pipeline stuff I continue to not figure out.
How would I write this?
<!-- For image lightbox you need to include "a" tag pointing to image link, along with the class "prettyphoto".-->
<div class="gallery">
<!-- Full size image link in anchor tag. Thumbnail link in image tag. -->
<img src="img/portfolio/1.jpg" alt="" class="img-responsive">
I've tried it twenty ways but I can't get it. A small image is suppose to come up and then when you click on it the image is larger. And I need to use the two existing classes as this is a bootstrap template conversion into Rails.
If it's in public/assets/images you can access it by saying:
<%= image_tag 'name_of_image.png', class: 'name-of-class' %>
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
<%= link_to 'name_of_image.png', object_path, class: 'name-of-class' %>
all! So I'm brand-spankin' new to SilverStripe, and while I've had success in modifying the 'Gallery' module to include an option to set the thumbnail size, I'm having issues using the thumbnail width/height values in my template. The code below does not show any of the gallery images (if I hardcode a width and height, such as 250,250 they display)-- but after the loop where I display the $ThumbWidth and $ThumbHeight values, those are displaying just fine...so I know those values are available to the template.
<% loop OrderedImages %>
<a class="fancybox" data-fancybox-group="gallery" href="$Filename" title="$Caption">
$SetSize($ThumbWidth, $ThumbHeight)
</a>
<% end_loop %>
Width: $ThumbWidth
Height: $ThumbHeight
So apparently, the $SetSize function is not liking the values I'm passing to it. Can someone shed some light on where my mistake is?
Thanks!
Bryan
From the SilverStripe forum:
Those variables are not set on the OrderedImage item which is the context of the loop. Use $Top.ThumbWidth and $Top.ThumbHeight as parameters.
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'm using a pagination example from balbus design. In the .ss template, there is a line of code:
<% control ProductList.PaginationSummary(5) %>
Is that possible to use a variable instead of hard-coding the value 5? For example:
<% control ProductList.PaginationSummary(PSSize) %>
The variable PSSize is defined in the model and will return the number set in the CMS.
The SS 2.4 templating language is very limited in terms of what it can do.
In this specific case, you could try working it out in the controller - try adjusting the $resultSet within ProductListPage_Controller::ProductList to preprocess the pagination summary to desired context size, so you can access it later from the template.
Try something like that:
$resultSet->AdjustedPaginationSummary = $resultSet->PaginationSummary($this->productsPerPage);
return $resultSet;
And then in the template you should be able to do:
<% control ProductList.AdjustedPaginationSummary %>