Is it possible to select different template (i.e. twig template) for same content type?
An Example:
3 blog posts, each displayed using different template...?
Template selected from a dropdown list during blog post creation?
use mixin
mixin different_blog_view_type(type)
....
if type !== "view1"
.supacoolEl23
.....
if type === "view2"
#moreCoolest2view
Don't forget to define locals.type variable, and change it your preferred way (dropdown,radio, so on)
exports = module.exports = function(req, res) {
var view = new keystone.View(req, res);
var locals = res.locals;
locals.type = req.params.type;
//this wil get from :type param
//or you can use req.body or req.query
Related
I have a custom entity field placed inside NetSuite, now I have to source the value of this field to my Reference Checkout as I'll use the value as a condition for which payment method to show on the shop.
Any ideas how to do this? I've searched the SuiteAnswers and got no significant help there.
Thank you!
I've looked into using view.model.get('customfield ID here') but it has not worked. I've also already defined the field on models.js. Just not sure if I placed it properly.
Render function of Order Wizard Payment Method Selector
, render: function()
{
if (this.wizard.hidePayment())
{
this.$el.empty();
this.trigger('change_label_continue');
return;
}
if (!this.selectedModule)
{
var selected_payment = this.model.get('paymentmethods').findWhere({primary: true})
, selected_type;
var creditlevelhold = this.wizard.model.get('creditlevelhold'); < -- this is the custom field
console.log(creditlevelhold);
if(selected_payment){
selected_type = selected_payment.get('type');
}
else if(this.wizard.options.profile.get('paymentterms') && creditlevelhold === ''){
selected_type = 'invoice';
}
this.setModuleByType(selected_type)
Should be available like:
this.wizard.model.get('options')['custbodyxxx']
I tested this with the default out of the box implementation and GetViewPage retrieves the view from the file system without a problem.
I swapped out the RazorFormat's VirtualFileSource for the inmemory one:
Plugins.Add(new RazorFormat() {
VirtualFileSources = new InMemoryVirtualPathProvider(this),
});
In the service I'm writing a view if it doesn't exist:
var helloView = razor.GetViewPage(email.BlastId.ToString());
if (helloView==null)
{
((InMemoryVirtualPathProvider)razor.VirtualFileSources)
.WriteFile("~/views/"+email.BlastId + ".cshtml", email.Blast);
// .WriteFile(email.BlastId + ".cshtml", email.Blast); doesn't work
}
helloView = razor.GetViewPage(email.BlastId.ToString());
//helloView is always null
I've confirmed that the RazorFormat's VirtualFileSource has the file, the GetViewPage just doesn't retrieve it.
Screenshot of the file located in the VirtualFileSource: https://db.tt/8oirKd9Msi
Furthermore this returns true: razor.VirtualFileSources.FileExists("~/views/"+email.BlastId + ".cshtml") I've tried it without the views folder/etc. It doesn't seem to make an impact.
The RazorFormat loads compiled views on Startup, so the view needs to exist in the VirtualFileSources before RazorFormat is registered in order for it to be available with GetViewPage().
To add a file after RazorFormat has loaded, you need to call AddPage() after it's written to the Virtual File System, e.g:
razorFormat.VirtualFileSources.WriteFile(filePath, contents);
var razorView = razorFormat.AddPage(filePath);
If you only wanted to create a temporary Razor View you can call CreatePage() to create the view:
var razorView = razorFormat.CreatePage(razorHtml);
And render it with:
razorFormat.RenderToHtml(razorView, model);
Or if both the Razor Page and model is temporary, it can be condensed in the 1-liner:
var html = razorFormat.CreateAndRenderToHtml(razorHtml, model);
Working Example
const string template = "This is my sample view, Hello #Model.Name!";
RazorFormat.VirtualFileSources.WriteFile("/Views/simple.cshtml", template);
var addedView = RazorFormat.AddPage("/Views/simple.cshtml");
var viewPage = RazorFormat.GetViewPage("simple"); //addedView == viewPage
var html = RazorFormat.RenderToHtml(viewPage, new { Name = "World" });
html.Print(); //= "This is my sample view, Hello World!"
I want to share some data from template to another template using Meteor. I have a template i.e allInventory.html on which i am showing some data in table form i added three links there that is. one for view , edit and delete what i want iam getting all the data from backend into one of helper i.e productDetails and i bind an event with view button that will take the data of current user clicked on which product so i have successfully getting the data at my allinventory template but there is another template i.e productDetails on which i want to render or show that data. But stuck with that i have data on allInventory click event but not know how do ishare the same with productDetails template.
Here is my allInventory.js
Template.allInventory.rendered = function() {
Template.allInventory.events({
"click .btn":function (e){
data = $(e.target).attr('data');
Router.go('productDetail', {data: $(e.target).attr('data')}, {query: 'q=s', hash: 'hashFrag'});
console.log("button clicked.."+data);
console.log(data);
}
})
ProductDetails.js
Template.productDetail.rendered = function () {
Template.productDetail.helpers({
productDetails: function() {
return data;
}
});
allInvenrtory.html
<button type="button" data ="{{productInfo}}" class="btn btn-info btn-sm"><i class="fa fa-eye"></i>View</button>
I just simply want to share allInventory template data with productsDetails template.
Any help would be appriciated!
Thanks
I'd recommend avoiding Session for this purpose, since it is a global object, but more importantly, because there are better ways to do it.
You can pass data from the parent templates to the child template using helpers: https://guide.meteor.com/blaze.html#passing-template-content
You can pass data from the child to the parent templates using callbacks https://guide.meteor.com/blaze.html#pass-callbacks
I'd structure this app to have a container (page) template, which will have all the subscriptions and render one of your templates based on the URL.
You can use the Session variable if you want to share data between templates.
You can follow this guide:
http://meteortips.com/first-meteor-tutorial/sessions/
I would put both template in a third, parent template.
ParentTemplate
-SharedInfo
-KidTemplate1
-KidTemplate2
Then having this third template hold the information you want to share across templates.
For that you can use a ReactiveVar, ensuring that change by template1 code on the parent template is visible in template2 as well.
To access the parent template for the kids, you can do something along those lines :
Blaze.TemplateInstance.prototype.parentTemplate = function (levels) {
var view = Blaze.currentView;
if (typeof levels === "undefined") {
levels = 1;
}
while (view) {
if (view.name.substring(0, 9) === "Template." && !(levels--)) {
return view.templateInstance();
}
view = view.parentView;
}
};
Background
I got a page where I’m showing two list views from two separate lists which both have Custom List as their ListTemplate. They got their separate jslink file cause I don’t want them to look alike.
Problem
The js link file targets both listviews since they use the same Template.
Code
(function () {
var listContext = {};
listContext.Templates = {};
listContext.ListTemplateType = 100;
listContext.Templates.Header = "<div><ul>";
listContext.Templates.Footer = "</ul></div>";
listContext.Templates.Item = LinkTemplate;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(listContext);
})();
Question
Is there any way to make the js only target a specific list?
Ended up going with Paul Hunts solution that he writes about on myfatblog.co.uk. http://www.myfatblog.co.uk/index.php/2013/09/listview-web-part-issues-with-jslink-and-display-templates-a-solution/
The script ended up looking like this and I pasted it into the jslink function where I define what listContext to override.
// Override the RenderListView once the ClientTemplates.JS has been called
ExecuteOrDelayUntilScriptLoaded(function(){
// Copy and override the existing RenderListView
var oldRenderListView = RenderListView;
RenderListView = function(ctx,webPartID)
{
// Check the title and set the BaseViewId
if (ctx.ListTitle == "List")
ctx.BaseViewID = "list";
//now call the original RenderListView
oldRenderListView(ctx,webPartID);
}
},"ClientTemplates.js");
I have written a helper function (I'm quite proud of this it - look what I can do!) that does what I need. Is there a built in way, though, to access a ContentItem's fields without having first to get the "main" ContentPart? The word "main" here means the ContentPart with the same name as the ContentType.
#functions
{
dynamic GetMainPartFromContentItem(ContentItem item)
{
var contentType = item.TypeDefinition.Name;
var parts = item.Parts as List<Orchard.ContentManagement.ContentPart>;
dynamic mainPart = parts.First(p => p.PartDefinition.Name.Equals(contentType));
return mainPart;
}
}
dynamic mainPart = GetMainPartFromContentItem(contentItem);
var shortTitle = mainPart.ShortTitle.Value; // access an InputField's value
If you have a ContentType called Page with a field called Topic you can do:
dynamic item = Model.ContentItem;
string topic = item.Page.Topic.Value;
Basically when you add fields directly to the content item, they are being added to a part on your content item called whatever your content type is, in this case Page