Umbraco 4.9 Display Media Picker Image in Template - umbraco

I'm trying to allow content editors to be able to choose the main banner image on a page by having it chosen through a Media Picker property.
I've tried the standard inline XSLT of:
<umbraco:Item runat="server" field="banner" xslt="concat('<img src="', umbraco.library:GetMedia({0},0)/umbracoFile, '" />')" xsltDisableEscaping="true" />
But in my simple template of:
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<header class="home-header">
<div class="logo-wrapper">
<umbraco:Item runat="server" field="banner" xslt="concat('<img src="', umbraco.library:GetMedia({0},0)/umbracoFile, '" />')" xsltDisableEscaping="true" />
</div>
</header>
</asp:Content>
The rendered HTML comes out at:
<header class="home-header">
<div class="logo-wrapper">
</div>
</header>
I've read about using a macro to render images but my Umbraco knowledge is limited. If someone could provide steps for actually adding an XSLT macro, I'd be happy to try that out.
Unfortunately we are stuck on Umbraco v4.9 for now too so no <umbraco:Image /> tag for me.

I suggest you use a c# Umbraco macro instead of xslt. Umbraco 4.9 can do that.
An macro can in a differt file or simple use a inline macro:
<umbraco:Macro runat="server" language="cshtml">
#if (#Model.visual != "")
{
<img src="#Model.Media("banner", "umbracoFile")" class="foto" />
}
</umbraco:Macro>
Same as <img src="#node.Media("banner", "umbracoFile")" />

If anyone else finds this and you are not using MVC you can use this approach inside your template to get the image path you selected from the media picker
<umbraco:Item field='headerImage' runat='server'xslt='umbraco.library:GetMedia({0},true())/umbracoFile'xsltDisableEscaping='true'></umbraco:Item>
Where headerImage is the alias for your attribute name in your document type. This will render something like "/media/1002/sample.jpg" for instance

Related

Localising HTML text using DevExtreme & Globalization

I am currently adding globalization to an existing web app which uses devextreme to present the page, as below:
<body>
<div id="viewport" class="dx-viewport">
<div class="startPage dx-content-background" data-options="dxContent : { targetPlaceholder: 'content' } ">
<div class="content">
<h1>Registration</h1>
<div class="regForm" id="registrationForm" />
<div class="regButton" id="registrationButton" />
<div class="loadIndicator" id="loadIndicator" />
<div class="registrationSucceeded" id="registrationSucceeded" />
<div class="returnToMainPageButton" id="returnToMainPageButton"/>
</div>
</div>
</div>
The entries are translated as expected but I can't figure out how to translate the heading as DevExtreme doesn't provide a straight 'Text' widget. If I set it to use a TextArea, for example then it does work but then obviously doesn't look like a header.
So, how can I translate the header text (or any other that is held in the HTML page)?
Maybe the official DevExtreme localization topic will be usefull for you.
So, how can I translate the header text (or any other that is held in the HTML page)?
You can use a text binding to provide content based on current locale.

How to implement my own login page instead of default Spring Security login page in Grails application?

I have gone through some of the blogs in internet, but I am not able to find out how to do my own login page without Spring Security. How can I do it?
To create a custom login page, create a view called auth.gsp in grails-app/views/login/. Make sure it passes the parameters j_username and j_password to the action ${postUrl}. Here is the default auth.gsp view that comes with Spring Security 1.x:
<html>
<head>
<meta name='layout' content='main'/>
<title><g:message code="springSecurity.login.title"/></title>
<link rel="stylesheet" href="${resource(dir: 'css', file: 'auth.css')}" type="text/css">
</head>
<body>
<div id='login'>
<div class='inner'>
<div class='fheader'><g:message code="springSecurity.login.header"/></div>
<g:if test='${flash.message}'>
<div class='login_message'>${flash.message}</div>
</g:if>
<form action='${postUrl}' method='POST' id='loginForm' class='cssform pure-form pure-form-aligned' autocomplete='off'>
<p>
<label for='username'><g:message code="springSecurity.login.username.label"/>:</label>
<input type='text' class='text_' name='j_username' id='username'/>
</p>
<p>
<label for='password'><g:message code="springSecurity.login.password.label"/>:</label>
<input type='password' class='text_' name='j_password' id='password'/>
</p>
<p>
<input type='submit' id="submit" class="btn" value='${message(code: "springSecurity.login.button")}'/>
</p>
</form>
</div>
</div>
<script type='text/javascript'>
<!--
(function() {
document.forms['loginForm'].elements['j_username'].focus();
})();
// -->
</script>
</body>
</html>
I would copy that into your auth.gsp view and change it from there.
This can be annoying sometimes.
So if am getting you right you want to change the look and feel of the login spring security offer right?
Do this after you are done with your UI design( CSS, HTML and others).
Now change the input name and compare it to auth.gsp, thus from Spring security.
You can hold ctrl+shift+N on the keyboard and type auth.gsp for you to check.
Compare it to yours and change where possible.
In your UrlMAppings.groovy do this editing
"/"(view:"/Your login page")
"/login/auth"(view:"/Your login page")
Now restart your service and thats all.
If the issue persist you can post the error here so we can see what to do to help.
Note this is for Grails 3.x
In order to do this you need to do this tasks:
Create a login view inside views directory
create two gsp views names auth.gsp and denied.gsp
in this step you probably need to copy content from plugin auth.gsp view and denied.gsp if you are using grails spring security core plugin version 2.0-RC3 these views are located at target > work > plugins > spring-security-core-2.0-RC2 > grails-app > view > login, copy content and paste it in your app auth.gsp and denied.gsp views
You can check an example of views location and views content in this repo.

MVC 3 - _Layout.cshtml. Add a logo to the site

I'm new to MVC 3, I'm trying to add an Image to the _Layout.cshtml file.
I tried
<img runat="server" id="img_logo" alt="Logo" src="Content/Images/mailworks.png" />
no success. The logo only appear on some views. on others views for some reason the image is supposed to be in some other location - found it using firebug.
Try this:
<img id="img_logo" alt="Logo" src="#Url.Content("~/Content/Images/mailworks.png")" />
Use this:
<img src="#Url.Content("~/Content/Images/mailworks.png")"...
I found another quick solution : just append '/' at the beginning of the src's path.

Is it possible to add dynamic jQuery tabs using KnockoutJS Templates?

I'm trying to build a dynamic display in a web page. The site is built in ASP.NET MVC 3, but I'm not sure if this matters...
Essentially, I have a base "_Editor.cshtml" page which uses partials to render the specific editor content in my display using query parameters. Consider an editor for a chart (line chart vs. bar chart).
_Editor.cshtml
<div id='tabs'>
<ul>
<li><a href='#queryTab'>Define Query</a></li>
<!-- THIS IS WHERE I NEED TO SHOW ALL OF MY 'CUSTOM' TAB NAMES -->
<!-- ko template: 'tabNames' -->
<!-- /ko -->
<li><a href='#themeTab'>Styles and Themes</a></li>
</ul>
<div id='queryTab'>
<!-- configure db connection, tables, fields, etc... (not important) -->
</div>
<!-- THIS IS WHERE I WANT TO SHOW CONTENT FOR MY CUSTOM TABS -->
<!-- ko template: 'tabContent' -->
<!-- /ko -->
<div id='themeTab'>
<!-- show various style options here (not important) -->
</div>
</div>
<script type="text/javascript">
$(function(){
var vm = { /* define my model here */ };
ko.applyBindings(vm);
$("#tabs").tabs();
});
</script>
#if (Model.EditorType == ChartTypes.Bar) {
#Html.Partial("_BarChartEditor")
} else if (Model.EditorType == ChartTypes.Line) {
#Html.Partial("_LineChartEditor")
}
_BarChartEditor.cshtml
<script id="tabNames" type="text/html">
<li>Bar Chart Tab!</li>
<!-- I could have many more tab names here -->
</script>
<script id="tabContent" type="text/html">
<div id="barChartTab">
<h1>Add controls for bar chart configuration</h1>
</div>
<!-- I would create a div for each tab name above here -->
</script>
_LineChartEditor.cshtml
<script id="tabNames" type="text/html">
<li>Line Chart Tab!</li>
</script>
<script id="tabContent" type="text/html">
<div id="lineChartTab">
<h1>Add controls for line chart configurations</h1>
</div>
</script>
Sorry for the lengthy code drop (it took a long time to write it all here, so have mercy on me). :) I wanted to make sure that my problem was understood because of the way I'm building my editors using custom partials. Perhaps it's cludgy, but it works for the most part...
Really, everything works great except for the tab content. The tab rendering appears to be happening before I'm able to bind my view model to the UI. When the 'ko.applyBindings()' method is called, the tab shows up on different tabs.
Has anybody tried to do this? Has anybody had success? I've created a jsfiddle to show a simple scenario to show exactly what I'm talking about:
http://jsfiddle.net/TrailHacker/j2nhm/
Thanks for any help!
I actually got it working with your example, your content template was just structured incorrectly. It was missing the <div> tags.
If you modify this for your example, just remember that the div id needs to match the link's ref. You can throw both of these values into your viewmodel, to allow for multiple custom tabs.
http://jsfiddle.net/tyrsius/UCGRZ/

How to integrate Yoxview to Rails 3 application when pictures are protected by Controller?

I'm trying to integrate Yoxview to my Rails 3 application that uses Paperclip to upload pictures.
The main problem is that the pictures (both original and thumbs) are not in the public area, i.e. they are accessible via Controller as described here.
The relevant HTML looks like:
<div id="my_wrapper">
<img src="/assets/1/thumb" />
<img src="/assets/2/thumb" />
</div>
When a thumbnail is clicked, I expect the Yoxview player to be opened, but what happens is that the original picture is opened in a browser.
When the pictures are in the public area like this:
<div id="my_wrapper">
<img src="/images/thumbs/1.jpg" />
<img src="/images/thumbs/2.jpg" />
</div>
everything works perfectly!
Any ideas ?
UPDATE
I tried also:
<div id="my_wrapper">
<img src="/images/thumbs/1.jpg" />
<img src="/images/thumbs/2.jpg" />
<img src="/assets/1/thumb" />
<img src="/assets/2/thumb" />
</div>
Here, if I click on thumbs/1.jpg or thumbs/2.jpg the player is opened properly, but shows only these two (original) pictures. If I click on one of the other two thumbs, their original picture is opened in a browser.
I found the answer. It's so simple. Just had to use the allowedUrls option of Yoxview:
allowedUrls: /^\/assets\/\d+\/(thumb|original)$/i

Resources