I have the following structure:
How do I access to Features of current Product in template?
Do you have any sample code? You would probably use the Children property. It would be something like
#foreach(var child in CurrentPage.Children)
{
<span>#child.featureName #*Or whatever field you have on feature*#</span>
}
They put out a cheat sheet which is always handy.
Related
I'm using Polymer and I am encountering a Problem. I think there is a good solution, but I still don't have the perfect understanding of polymer.
In my template I get a dom-repeat which gets me some _itemsas item. item.name returns the name of the item, it works just fine. Now I want to use this name to display it in a tooltip, so I call the function on-mouseenter="_showTooltip".
My function looks like this:
_showTooltip: function(e) {
var item = Polymer.dom(e).rootTarget;
//........here I get Information out of my item to use it in my tooltip and display it
}
How can I transfer the information of my original item to this function?
Thanks in advance!
You did not mention or tag which version of Polymer you're using so I will point you to the docs for Polymer 2 because that's what I use, but I am guessing something similar must exist for Polymer 3 also.
Any event triggered from elements rendered inside a dom-repeat will get a model key added, under which you will have the context, so you will have your item from HTML there.
You can see that in the docs here.
To start you can try to:
_showTooltip: function(e) {
var item = Polymer.dom(e).rootTarget;
//........here I get Information out of my item to use it in my tooltip and display it
console.log(e.model); debugger;
}
and continue from there..
I have a collection of some items. Using * symbol I set user control (ascx) in presentation details for all of them. Now I have a problem because on of this items has to be display in another control. Is there some trick that allow me to change used control dynamically, for example checking url segment?
I'm guessing you're using wildcard item called * with some presentation details defined on it. And now you want to display different components for one you the urls?
If you want to have completely different presentation, you can add another item as a sibling of the * item and put new presentation detail there. This item will be matched before the wildcard item, if the url segment is equal to this item name.
If you want to change only one or few components, you can use personalization for this component and where the item name compares to ... rule.
Marek's answer is preferable, but for completeness I will provide another potential option.
It depends on how you are handling the wildcards. I don't think it will work if you are using the wildcard item module from the Marketplace and it might not play well with some of your existing code, but here goes...
You could place the required presentation details on the target items themselves. Then when you resolve the wildcard, you would need to change the context item to be selected target item. When the page loads, it will use the presentation of the newly set context item.
One way to achieve this would be to create a custom item resolver
class WildCardItemResolver : ItemResolver
{
public override Process(HttpRequestArgsargs args)
{
base.Process(args);
// if Context.Item is as wildcard
// look up the target item
Context.Item = targetItem
}
}
We have to display the following view:
Categories (displayed as tables), each category table should have products (tr).
How can we structure it using Marionette itemView and CompositeView?
We need the product to be an itemView.
Should we make each category as CompositeView, and have more than one CompositeView? or is there any other alternative to include all compositeViews into a single item, like:
Collection(CompositeView???)
-> CompositeView-category1
-> itemView-product1-1
-> itemView-product1-2
-> CompositeView-category2
-> itemView-product2-1
-> itemView-product2-2
I would suggest you to use a Layout view, inside this layout you can have a region for each category and draw your composite views on these regions.
the benefit of the Layout view in marionette is that you can pass a template that should contain all the HTML that you need initially, for example a header with buttons to add and remove categories etc.
CategoriesLayout = Backbone.Marionette.Layout.extend({
template: "#layout-template",
regions: {
category1Region: "#category1",
category2Region: "#category2"
}
});;
and then you can render your composite views inside the regions
categoriesLayout = new CategoriesLayout();
categoriesLayout.category1Region.show(new CategoryView());
this way you can show/close your views using the Region functionality. If you need to add the regions on the fly that is also possible if you render the HTML with Marionette.renderer and then attach your regions to the Layout.
additionally you may want to take a look at the region manager of Marionette that helps you to manage a set of regions.
EDIT
I did a jsfiddle to demonstrate this, this is just an example but I think the idea is there...
http://jsfiddle.net/VS9hA/28/
MyLayout = Backbone.Marionette.Layout.extend({
template: "#layout-template",
regions: {
menu: "#menu",
}
});
var layout = new MyLayout({el:"#container"});
layout.render();
var dynamicRegion = sampleModel.get('categoryName');
layout.addRegion(dynamicRegion,"#dynamic"); // adding the region on the fly
layout[dynamicRegion].show(sampleView); // using it!
so the answer to your question in the comment
categoriesLayout[dynamicRegion].show(new CategoryView())
just make sure the DOM element is there (#dynamic) if its not, just append the HTML on your layout view or use the marionette.Renderer Object to pass a nice template for your region.
And there is no problem adding a region on the fly, marionette has a method for that scenario.
Hope that helps,
I would advise against using Layouts for your top level view because then you have to manually create a region for each new category you add. Using a CollectionView or CompositeView on the other hand allows for an unlimited number of categories (and even an emptyView when there are none) without extra work.
The decision of whether to use a CompositeView or CollectionView as the top view will depend on whether or not you need a template wrapper for it (for buttons, etc). If you don't then just go with a CollectionView.
I think you're on the right track with each category being a CompositeView so you can have the template with tbody as the 'itemViewContainer':
<table>
<tbody>
</tbody>
</table>
in the category view:
itemViewContainer: 'tbody'
And then the products (ItemViews) will use:
tagName: 'tr'
I have a reference site for a series of books, and I'd like to make it so that readers can avoid spoilers. The idea I had was to make a setup webpage where they click on a checkbox for each book from which they want to see info. I could then store that (somehow) as a cookie for each time that they visit the site, plus have it work for each page in the site. So, one page might have this:
<li class="teotw">Rand killed a Trolloc</li>
and another page might have
<li class="teotw">Nynaeve tugged her braid</li>
and that information would not show up on the page unless they had checked the box for the "teotw" book. My initial thoughts are to do something like toggling the CSS class value like this:
document.styleSheets[0]['cssRules'][0].class['teotw'] = 'display:none';
document.styleSheets[0]['cssRules'][0].class['teotw'] = 'display:inherit';
but I'm not sure if this is the best method. Firstly, it would only apply to the current document only so I'd need a way to re-apply it to each page they visit. I'm using YUI as well, if it matters.
Any ideas on the best way of doing this?
There are many ways to implement it. You can use the YUI Stylesheet module (read its User Guide for how to use it) which will do what you're considering with cross-browser support and it's much easier to use than using the DOM directly.
Another way would be to add classes to the body of the page. You can define styles like this:
.teotw {
display: none;
}
.teotw-visible .teotw {
display: block;
}
With the following JS code:
if (someCondition) {
// show the hidden content
Y.one('body').addClass('teotw-visible');
}
For the persistance of the visible state you can use cookies with the YUI Cookie utilty or local storage with CacheOffline. Code using cookies would look something like this:
var body = Y.one('body');
if (Y.Cookie.get('teotwVisible')) {
body.addClass('teotw-visible');
}
// change the cookie
Y.one('#teotw-toggle').on('click', function (e) {
var checked = this.get('checked');
Y.Cookie.set('teotwVisible', checked);
body.toggleClass('teotw-visible', checked);
});
You should probably store the different sections in a JS object and avoid hard-coding class names in every JS line. Or maybe use a convention between checkboxes IDs and section class names.
I have a problem at which I have a view that will display a featured item and 6 rows on the first page of the view, while displaying 9 rows on the rest of the pages. Is such a functionality possible with views?
Thanks!
A few methods I can think of. I have mentioned them on the basis of how long it will take you.
1) Create a custom css rule which hides two entries on the first page. As for the rest of the pages you can show it.
2) Find the template file of your particular views and then use php to hide those rows. You can find the name of this file in your views theme section.
3) You could write a php module which can do the same as views. Its not that hard to get it done.
UPDATE
Below is the jquery which will help you get the logic right
$(document).ready(function() {
var pathname = window.location.pathname;
// here we assignt he current url of the page to the var pathname
});
if(pathname =='firstPageofView')
{
// if the path name is the first page of the view then we assign special css formating
$('#divid').hide();
}
else
{
$('#divid').css('width','10px');
}
Cheers,
Vishal