SilverStripe Using Field Values in Template - templates

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.

Related

How to write this Rails asset pipeline link

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' %>

Rails render is inserting a blank space

I'm pretty new to rails and I'm getting a weird issue when I try to render a partial. Instead of just rendering the HTML, it's adding a blank space surrounded by quotes above the partial's content.
> View (index.html.erb)
<div>
<%= render 'shared/rightColumn' %>
</div>
> Partial (_rightColumn.html.erb)
<div>
Some Content...
</div>
> Result...
<div>
""
<div>
Some Content...
</div>
</div>
This causes the content of my partial to be shifted down in the view because the browser is accounting for that blank space. If I add one comment before the call to render and another at the start of the partial's content, the blank space is added between the two comments.
I'd rather not add negative margins to try and hack my way around this. And Rails is used heavily enough that I'm sure this is my fault. I just can't figure a way around it. Should I not be using render? Or am I misusing it?
Thanks.
Make sure your CSS is reset.
* {
margin: 0;
padding: 0;
}

Sitecore Cache from Standard Value

One sublayout (.ascx) is using datasource from its template standard value.
Whenever I enable the cacheable setting with varyByData and varyByParm, I can't get all field values in __Standard Value of its template.
I checked cache.aspx page and it shows:
**web[standardValues]________0________0________0________10MB<br />
MaxSize is 10MB, but zero Count, zero Size and zero Delta information.**
Any ideas of how to solve this?
=============Update=============
I have fields in a template for CSS class names, such as h1, ul class, etc ... and all names initially set in its "__Standard Values".
Then, I have an item which calls the template's standard values as data-source.
This is another my post and it will help you more.
Sitecore Cache Issue
Could I know what the problem is?
=============Update 2=============
Current .cs file to get field values.
<asp:View ID="viewNormalMode" runat="server">
<nav class='<% Response.Write(myDataSourceItem.Fields["Nav Bar Class"]); %>'>
<h1 class='<% Response.Write(myDataSourceItem.Fields["Label h1 Class"]); %>'>
<i class='<% Response.Write(myDataSourceItem.Fields["Label i Class"]); %>'></i>
<% Response.Write(myDataSourceItem.Fields["Nav Bar Label"]); %>
</h1>
<ul class='<% Response.Write(myDataSourceItem.Fields["ul Class"]); %>'>
<asp:Literal ID="linkObjects" runat="server"></asp:Literal>
</ul>
</nav>
</asp:View>
Hope I understand correctly.
How Sitecore Cache work on sublayouts: Let take a main navigation (as sublayout) when you enable the cacheable setting global or from page to page you will get this result:
How your navigation looked at first page access after AppPool restart or application DLL update will look the same way on all other pages having cache on sublayout (even if you use another data source or something else, the code is cached/not executed).
But I think you have another bigger problem, move your fields for selection from Presentation Sublayouts on Data Template (Items) you will have huge problems on Locales. Beside you can add from code your classes as this:
You know your Layout, case you are in it, and you know you Context Item or your page definition Item, base on template name (Context.Item.TemplateName == "Article") put your CSS classes

How to display a youtube embed link that is called from database

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.

Inserting a variable argument into a Silverstripe template's function?

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 %>