I want to change the title of the page after any route has been rendered, to the name of that route. This is the code I was using before:
Router.after(function(){document.title = this.route.name;});
The manual mentions using onAfterAction inside an individual route, but I'd like to do it globally?
You must have missed this : http://eventedmind.github.io/iron-router/#using-hooks
The correct syntax is straightforward :
Router.onAfterAction(function(){
// your hook definition
});
Note : The guide is for iron:router#1.0.0-pre2 which must be added to your app explicitly like this :
meteor add iron:router#1.0.0-pre2
But the Router.onAfterAction works fine in iron:router#0.9.X too.
I suggest using this.route.getName() instead of this.route.name, see more about this issue here :
https://github.com/EventedMind/iron-router/issues/878
The router.after(); method although has been deprecated will still be allowed in the code in terms of syntax. As discussed in the IRC chat the best approach is to use the new syntax.
Router.onAfterAction(function(){
document.title = this.route.name;
});
This should resolve what you are looking for.
Cheers !
Ryan
Related
Why is this documentation :
https://symfony.com/doc/current/configuration/external_parameters.html#custom-environment-variable-processors
suggesting to use a tag (container.env_var_processor) that does not exist in :
https://symfony.com/doc/current/reference/dic_tags.html
When documenting the env var processors in https://github.com/symfony/symfony-docs/pull/10553, it was simply forgotten to add the tag to the reference. Would you like to send a pull request to add it there?
I tried mocking NavigationParameters and it is setting GetNavigationMode() as NULL. Is there any better way to mock an extension method?
Didn't work out for me. But your reference helped me to find a solution, that compiled (maybe it is a version issue, I use Prism 7.1:
var navParams = (INavigationParametersInternal)new NavigationParameters();
navParams.Add("__NavigationMode", NavigationMode.New);
This was bugging me for a while as well, and I finally found something that is at least a workaround. This issue shows that you can actually add internal parameters to the NavigationParameters, it just doesn't show up in intellisense. My test code ended up looking something like:
var navParams = new NavigationParameters();
navParams.AddInternalParameter("__NavigationMode", NavigationMode.Back);
Hope this helps!
As noted by #thomas-kison, the AddInternalParameter api no longer seems to exist. A search through the Prism repo only brings up the issue referenced by #batesiiic in their answer.
To add to #thomas-kison's answer by addressing #esteban-chornet's question, what I've found is that this solution will work by passing in the INavigationParametersInternal argument as INavigationParameters:
// arrange:
var navParams = (INavigationParametersInternal)new NavigationParameters();
navParams.Add("__NavigationMode", NavigationMode.Back);
// act:
_myCoolPageViewModel.OnNavigatedTo(navParams as INavigationParameters);
// assert whatever should happen in OnNavigatedTo given a NavigationMode of NavigationMode.Back
Hope this helps someone out!
Because I use plone.app.widgets (1.8.0) and wildcard.foldercontents (1.3.2), I have to disable pa.widgets-Javascript only for /folder_contents tab.
Multiupload does not work with pa.widgets enabled
().fileUpload is not a function
But how can I determine that?
What I've tried:
context/absolute_url
context/##plone_context_state/object_url
getViewTemplateId
and a few more
Plone 4.3.4.1
I had a similar issue with wildcard.foldercontents and collective.z3cform.widgets..both have a related js code that goes in conflict.
i check that condition like this:
self.request.steps[-1] != "folder_contents"
In folder_contents tab, last step in the request is always "folder_contents".
I don't know if it's the best solution, but it works
Sorry, just so simple
request.ACTUAL_URL
open for a better solution :-)
You could try the following code:
mt = getToolByName(self.context, 'portal_membership')
member = mt.getMemberById(username)
if member == 'Anonymous':
pass
else:
pass
And you can handle when is Anonymou or logged member.
i wond if it's anyhow possible to solve this problem with Spacebars in Meteor:
{{TplVar placeholder="{{mf 'identifier' 'defaultval'}}"}}
This sytnax causes a syntax error.
If the placeholder would not contain spaces - as far as i know - just keeping it free of curly brackets would solve the solutions but this doesn't work here.
I'm a bit at a wall now - should there be really no way to solve it? I've already searched around for jagged handlebars/spacebars template tags but couldn't really find anything useful - especially not for the Meteor context.
Thanks in advance for helping!
Frank
I've never used the Messageformat package (which looks interesting), but from the docs it looks like there's a javascript API. So you can just do something like:
{{TplVar placeholder=thisPlaceholder}}
and
Template.yourTemplate.helpers({
thisPlaceholder: function() {
return mf(this.identifier, this.defaultval);
}
});
Note that I'm assuming identifier and defaultVal are in the data context here - if they're the results from helper functions, you need to replicate those functions within this new thisPlaceholder helper and replace this.identifier and this.defaultval with the results.
I want to give my users the possibility to create document templates (contracts, emails, etc.)
The best option I figured out would be to store these document templates in mongo (maybe I'm wrong...)
I've been searching for a couple of hours now but I can't figure out how to render these document template with their data context.
Example:
Template stored in Mongo: "Dear {{firstname}}"
data context: {firstname: "Tom"}
On Tom's website, He should read: "Dear Tom"
How can I do this?
EDIT
After some researches, I discovered a package called spacebars-compiler that brings the option to compile to the client:
meteor add spacebars-compiler
I then tried something like this:
Template.doctypesList.rendered = ->
content = "<div>" + this.data.content + "</div>"
template = Spacebars.compile content
rendered = UI.dynamic(template,{name:"nicolas"})
UI.insert(rendered, $(this).closest(".widget-body"))
but it doesn't work.
the template gets compiled but then, I don't know how to interpret it with its data context and to send it back to the web page.
EDIT 2
I'm getting closer thanks to Tom.
This is what I did:
Template.doctypesList.rendered = ->
content = this.data.content
console.log content
templateName = "template_#{this.data._id}"
Template.__define__(templateName, () -> content)
rendered = UI.renderWithData(eval("Template.#{templateName}"),{name:"nicolas"})
UI.insert(rendered, $("#content_" + this.data._id).get(0))
This works excepted the fact that the name is not injected into the template. UI.renderWithData renders the template but without the data context...
The thing your are missing is the call to (undocumented!) Template.__define__ which requires the template name (pick something unique and clever) as the first argument and the render function which you get from your space bars compiler. When it is done you can use {{> UI.dynamic}} as #Slava suggested.
There is also another way to do it, by using UI.Component API, but I guess it's pretty unstable at the moment, so maybe I will skip this, at least for now.
Use UI.dynamic: https://www.discovermeteor.com/blog/blaze-dynamic-template-includes/
It is fairly new and didn't make its way to docs for some reason.
There are few ways to achieve what you want, but I would do it like this:
You're probably already using underscore.js, if not Meteor has core package for it.
You could use underscore templates (http://underscorejs.org/#template) like this:
var templateString = 'Dear <%= firstname %>'
and later compile it using
_.template(templateString, {firstname: "Tom"})
to get Dear Tom.
Of course you can store templateString in MongoDB in the meantime.
You can set delimiters to whatever you want, <%= %> is just the default.
Compiled template is essentially htmljs notation Meteor uses (or so I suppose) and it uses Template.template_name.lookup to render correct data. Check in console if Template.template_name.lookup("data_helper")() returns the correct data.
I recently had to solve this exact (or similar) problem of compiling templates client side. You need to make sure the order of things is like this:
Compiled template is present on client
Template data is present (verify with Template.template_name.lookup("data_name")() )
Render the template on page now
To compile the template, as #apendua have suggested, use (this is how I use it and it works for me)
Template.__define__(name, eval(Spacebars.compile(
newHtml, {
isTemplate: true,
sourceName: 'Template "' + name + '"'
}
)));
After this you need to make sure the data you want to render in template is available before you actually render the template on page. This is what I use for rendering template on page:
UI.DomRange.insert(UI.render(Template.template_name).dom, document.body);
Although my use case for rendering templates client side is somewhat different (my task was to live update the changed template overriding meteor's hot code push), but this worked best among different methods of rendering the template.
You can check my very early stage package which does this here: https://github.com/channikhabra/meteor-live-update/blob/master/js/live-update.js
I am fairly new to real-world programming so my code might be ugly, but may be it'll give you some pointers to solve your problem. (If you find me doing something stupid in there, or see something which is better done some other way, please feel free to drop a comment. That's the only way I get feedback for improvement as I am new and essentially code alone sitting in my dark corner).