SilverStripe draft content status - silverstripe

Is there an easy way to identify draft content when viewing draft pages/content on my website? I want the ability to identify draft content and style it differently to published content.
I was hoping to find something like:
<% if $status == 'draft' %>
...
<% end_if %>

SilverStripe pages are stored in SiteTree and SiteTree_Live tables. The former table contains draft content (internally called as Stage stage), and the later contains published content (Live stage). SiteTree_versions table contains all modified versions of the page.
When you request a page in production, it is read from Live stage by default. When you see preview in the CMS you can switch between stages.
You can get Versioned reading stage as following
<% if $CurrentReadingMode = 'Stage.Stage' %>
Draft content
<% end_if %>
<% if $CurrentReadingMode = 'Stage.Live' %>
Published content
<% end_if %>

You might have a look at the https://github.com/jonom/silverstripe-betternavigator module which shows a nice red (draft) or green (live) status bar (and a handy menu for e.g. editing this page) in the right upper corner:
Just install it using composer and put $BetterNavigator somewhere in your template(s). If your website uses caching, make sure BetterNavigator's output is excluded.
You can also configure it so that it's just shown when you're in dev mode or logged in.
I normally use something like this to avoid showing it to everyone when I'm in dev mode:
<% if $CurrentUser %>
$BetterNavigator
<% end_if %>

Related

How to access two pages with the same url part in SilverStripe template

does anybody know how to solve following ?
I have in SilverStripe two different pages with the same name and url, but in different hierarchy structure.
www.example.com/xyz/url-part
www.example.com/abc/url-part
I would like to access this pages in template as
<% with Page('url-part') %>
$Title
<% end_with %>
but I'm not able to differ these two pages. Any ideas?
here we go #MartinRázus :)
<% loop $Children.filter(URLSegment, "url-part") %>$Title<% end_loop %>

my web page is running in chrome or not?

How can i check whether the webpage is running in Chrome or not?
if not alert the user that you are not running in chrome:
the scenario will be like this:
IF webPage is not running in Firefox then
msgbox("You are not running in chrom")
End if
Can any one help me to do like this? am using Asp.Net with VB
You'll want to check the value of HttpRequest.UserAgent - the contents of this can vary wildly across browsers (here's a few examples), but in general a Chrome user agent will contain a part like Chrome/37.0.2062.124
So in your .aspx page, you could have something like this:
<% If Not HttpRequest.UserAgent.Contains("Chrome/") Then %>
<script type="text/javascript">alert("You are not using the Chrome browser");</script>
<% End If %>
(I put the <% %> in because this doesn't go in the .aspx.vb backend page)

Server tags not working inside asp controls

Alrighty to make this quick:
I want to set start and end dates for a calendar extender dynamically on-change or on page load
the values are put into hidden fields on the .ascx and populated during page load in an if not postback
one set of calendar extenders is in the item template field of a grid view call this set A
the others are in a normal html table - set b
set a and set b have flags StartDate="<%# hfStart.value%>" EndDate="<%# hfEnd.value%>"
set a in the item template of a grid view column works like a charm
set b in the HTML table doesn't appear to work at all
What gives?
So far I have tried other server tags with the same code inside but I am obviously missing the salient detail. Why does one work and not the other?
UPDATE: Tried
CDate(hfstart.value).ToString with <%: and <%= tags
<%= hfstart.value %>
Unless I misunderstand, <%= will fire at the very END of the asp.net life cycle stopping it from being useful in this context.
As it turns out you DO need to use <%# %> within asp tags as others like <% %> and <%= %> execute at the end of the ASP.NET life cycle and get spit out the buffer to god knows where. When using <%# %> however, the asp control needs to be DataBound(); at the appropriate time.
This happens automatically for controls modeled in the <item template> tags in the gridview because everything within the gridview is bound on its gridview.DataBound() command.
Could it be because you're using the <%# %> tags which are for data binding? This would explain why they work in the GridView, because it supports data binding.
However in a basic HTML table you should use <% %> tags instead, or <%= %> to call a method.
For full details of the tag types, try this reference.

Rails 3 Ajaxful_rating Styling Issue

I'm using the ajaxful_rating gem for a user rating system in my rails app and I came across a weird styling issue:
As you can see there's much too many stars, there shouldn't be more than 5. I used Ajaxful_rating before in a previous app and didn't run into this problem. I recently started using Twitter Boostrap but as far as I can tell there aren't any styling conflicts as I removed every css link except the one needed for ajaxful_rating and I had the same issue.
Here's my view:
<dl>
<% Upload.by_ratings.limit(5).each do |upload| %>
<dt><%= link_to truncate(upload.name, :length => 55), upload%></dt>
<dd><%= upload.user.username %> - <%= ratings_for upload, :static %></dd>
<% end %>
</dl>
Has anybody ran into this problem before?
The problem was that I was directly linking to the css in my layout. I had forgotten that I needed to call the helper method ajaxful_rating_style instead.
place <%= ajaxful_rating_style %> in your javascripts.

What is the practical difference between Response.Write and <%= %>?

I've run into an issue where a third-party component appears to be interfering with Response.Write and causing any content within Response.Write("") to render before any of the other html. For example:
<html><head><title><% Response.Write("HELLO WORLD") %>
will render as
HELLO WORLD<html><head>...
However, any content rendered using <%= %> blocks will work correctly. The below code will work perfectly:
<html><head><title><%="HELLO WORLD"%>
I always assumed that <%= was simply shorthand for Response.Write. From what I've been able to find on MSDN I now understand that it <%= is eventually converted to Response.Write, but apparently there are a few steps inbetween.
Does anyone have a guess as to why the two would render differently or point me to some documentation/info that explains how <%= %> blocks are handled?
Update: The control that was causing the issue was the Telerik AjaxManager control from the 2009 Q1 release. Upgrading to the Q2 control resolved the problem.
Unfortunately I don't have access to the source so I haven't been able to figure out why the control was causing this behavior. The issue has been resolved but I am still very curious as to why it existed in the first place.
<%= "foo" %> is turned into Response.Write("foo"); once it is compiled. You can verify this by digging through the ASP.NET Temporary Files folder and using Reflector to decompile the dll's you find.

Resources