I was wondering if I can somehow access twig in action to use it's escaping function? I need this because I am converting text with markdown and will need to show it raw in templates, but want to escape it before I save it.
Can I access twig service somehow and what function would I call?
It's a bad idea to modify user input before persisting it. You should persist it as is and transform on output. If you are concerned about the performance of this approach, caching is the answer.
The reason for this is that if you have a bug in your transormation logic or decide later to change it, you'll be in a trouble if you persist the transformed input.
BTW, take a look at a markdown bundle.
Related
I'm trying to build a form in which you can dynamically add text inputs as required. I don't want to save anything until the person clicks 'save' so it's important that this is done without a db collection.
I came up with this solution (http://meteorpad.com/pad/zP8EGjigXASfFrXsF/Input%20Test) but I'm unsure if this is the correct approach or is there an easier way?
Most users probably don't need to directly use Tracker.Dependency anymore because there are now higher-level options that are are a bit easier to use. Here are two choices:
Client Collections
You can declare a client-side collection like:
InputOptions = new Mongo.Collection(null);
It will have all of the same behavior as a normal collection without trying to sync its data to the server. This is probably what you want. The only disadvantage is that the collection will be available to your whole application, so its reactivity is not isolated to a single template.
ReactiveVar
You can use either a ReactiveVar or a ReactiveDict and scope it to your template. This is a bit better than directly using Tracker.Dependency because you don't have to call changed all over the place. Overall the syntax is more cumbersome that a client-side collection, but you get the advantage of isolating the reactivity if you need more than one of them.
My first post here, I have always found the help I needed in previously asked questions ,thanks, but I'm stumped this time so here goes.
I'm still a novice relatively speaking to people on here, but I have developed a joomla 2.5 component and I need to store data in AES encrypted format.
Ok so for saving the data, I've done this by overriding the prepareTable function in the model when saving the data, and that works very well.
But where is the best place to decrypt the data when loading it back into the user forms?
For the list views I can just call my own decrypt function in the view or even the layout and that's ok too.
But when I go to actually edit an individual record, using the standard joomla myform.xml the data is loaded into the formfields unencrypted.
I need to override some built in part of Joomla so that I can decrypt the data before it is populated into the form fields.
Can anyone please advise what function I can override to change the data before it is displayed in the form.
Maybe I've missed something obvious but what I am looking for is the same as prepareTable but for loading data, rather than saving it.
Thanks in advance for any help.
Solved, with Elin's suggestion.
When saving data I encrypt the data using a php function in the override of prepareTable.
Then for reading the data back into the form I extend the JFormField to JFormFieldAes adding the decrypt logic in the getInput function.
For custom Select form fields I use the same logic but put it in the getOptions function.
I now have the ability to encrypt any fields I choose without having to use any database encryption. It was quick and easy in the end.
I am currently developing my first Meteor project, and as the code basis is growing, I am unsure about using session variables/ the reactive programming approach correctly. For example, let's have a look at a form for editing a blog article. Before editing, I use Session.set("current_article", Articles.findOne(id)) to set the current article. When opening the article form, everything is populated correctly by using <input type="text" name="title" value="{{article.title}}">.
But the form is much more complicated than just displaying the title:
E.g. when the title or a tag changes, the text on right the right (a generated tweet message) updates while typing. To achieve this, I register a keyUp listener that sets Session.set("current_article", $.extend(Session.get("current_article"), {tweet: someMagicTweetGeneration()})). You might already notice that the way I am using Session variables causes rerendering the whole template.
So my question is: Does it makes sense storing more complex objects (like articles) into a session variable? This way saving the form is quite straightforward, but it obviously causes other issues. Should I split Session.get("current_article") into Session.get("current_article.title"), Session.get("current_article.tweet"), ...? Any other best practices?
You could use {{#isolate}}..{{/isolate}} blocks so that only bits of your template are re-rendered and not the entire thing, e.g with:
{{#isolate}}
<input type="text" name="title" value="{{article.title}}">
{{/isolate}}
So now when you change article.title only the bits inside this isolate block will be changed, and everything surrounding will be untouched.
You do have to re-render bits of the DOM that change, so the idea is to only re-render the bits that need to be redrawn.
As for the Session variables, try storing them in a manner where if you send out the variable to the DOM, to avoid sending one large object and instead send only the pieces that are required for a template.
E.g in the above you might have many things used in {{article}}, but you only use {{article.title}} in that bit of code, so it might be better to use only template. If you know you're going to use all of them then you might as well use nested objects.
I want to bet on meteor getting better and better, so we don't have to jump through those kinds of hoops. I imagine you already know about http://docs.meteor.com/#template_preserve.
I would suggest you try splitting the data into two distinct structures in the session, main and sidebar. Have each template react to only one or the other. That may even be a reasonable schema for your mongo collections.
I read something about optimizing that suggested you store ids in the session, rather than whole objects, then just findOne for the collection.
Is this a hypothetical problem, or are there symptoms you are bothered with?
i use customfiel php code inside one of my views to translate a string since 2.x of views is bad at localization. i use the following php code:
echo t('Watch Video');
but the string does not appear in the "translate interface" section.
thanks for your help.
lukas
The accepted answer is wrong, as the localization script is not scanning anything. The string is registered in the translate interface as soon as it gets passed through the t() function for the first time in the non-standard language.
Therefore, for translation it doesn't matter if the code you are writing is eval'd (interpreted from the database) or exists in the source. Obviously good practice would be to keep code in files where it belongs.
This blog post describes what needs to be done to get your strings into the translate interface.
The localisation database is built by scanning the source code, looking for instances of the t() function (and Drupal.t() in Javascript).
If the code in question has been entered into a text box in the Drupal admin area, then it isn't in the source code, so it won't be picked up by the localisation process.
For this reason (and others), you should put as little code as possible into the admin text boxes. There is usually an alternative way to achieve the same thing, but even if there isn't, you should reduce the code to a minimum -- best practice would be to have nothing there except a single line function call: have it call a function, and write the function code in your module or theme. That way it will be parsed when you run the localisation.
Background: I have a complex search form that stores the query and it's hash in a cache. Once the cache is set, I redirect to something like /searchresults/e6c86fadc7e4b7a2d068932efc9cc358 where that big long string on the end is the md5 hash of my query. I need to make a new argument for views to know what the hash is good for.
The reason for all this hastle is because my original search form is way to complex and has way to many arguments to consider putting them all into the path and expecting to do the filtering with the normal views arguments.
Now for my question. I have been reading views 2 documentation but not figuring out how to accomplish this custom argument. It doesn't seem to me like this should be as hard as it seems to me like it must be. Leaving aside any knowledge of the veiws api, it would seem that all I need is a callback function that will take the argument from the path as it's only argument and return a list of node id's to filter to.
Can anyone point me to a solution or give me some example code?
Thanks for your help! You guys are great.
PS. I am pretty sure that my design is the best I can come up with, lets don't get off my question and into cross checking my design logic if we can help it.
It's not as easy as you would like to make it.
In views, arguments are used to return objects, fx user, node, term, custom object. So you could make some custom code, to get the "query object". That would only be first step. You then need to get the info from the query object. You could either try making a custom relationship bond with the nodes or build your own filter to make the SQL needed. This can quickly become a confusing time sink.
Instead, I would suggest that you use hook_views_query_alter, which will allow you to alter the query. Since you already have the SQL, it's just a matter of checking for the hash, and if it's there, alter the query. Should be a pretty simple thing to do. Only thing that is a bit tricky, is that you have to make the query with the query object that views uses, but it's not that hard to figure out.