How to get a list of placeholders / variables in a word template - templates

using phpword, I would like to get a list of all the placeholders ${var_name} that is in a template
I have searched here and in the documentation but I have not been able to find a function that can give a list of placeholders / variables

I'm assuming you're referring to the PHPWord TemplateProcessor.It actually does provide a method that returns an array of all the variables in the template, which is $phpWord->getVariables() as refer to the source code. I found it when digging into the source code. The official documentation is long out of date.
Hope it helps!

Related

Code-completion support for Django template language in Pycharm

In the template files code-completion works well for html tags and for adding matching {%,
What I want is for eg: if I type blog. and Ctrl + Space, it should show me the options like blog_title,blog_author etc, that are associated with blog.
Is this possible at all?
I do not think it is possible as PyCharm has no knowledge of the type of objects you pass as context to the template. It could infer it from the view where the template is used but we are not there yet.
It is possible if you register your own template tags with explicit name in your code.
Example: register.tag ("page_attribute", PageAttribute)
See also: https://github.com/divio/django-cms/issues/3878 where the same thing came up.
PyCharm will recognize that and do as you asked.

How can I print a ctemplate::TemplateDictionary in JSON form?

Using the Google CTemplate library, I have built a TemplateDictionary of params. Such a dictionary is a map of string keys to a variety of value types.
Typically, one passes CTemplate a template file wherein placeholders for each key in the dictionary are found and substituted.
In one case, though, I wish to emit the entire dictionary in JSON form, and the template language syntax doesn't appear to provide reflection such that I can write placeholders to loop over an unknown number of unknown keys in any arbitrary dictionary.
Did I miss some functionality?
If so, how can I add it?
Will I have to patch the CTemplate code? Much of what I seem to need for the job appears to be marked private i.e. for internal use only...
I've ended up hacking the CTemplate source in template_dictionary.h and template_dictionary.cc, cloning class class TemplateDictionary::DictionaryPrinter to produce a new class class TemplateDictionary::DictionaryJsonPrinter, adapting its member functions to emit JSON syntax.

How I do find properties name list of a object

JSAPI provide function JS_GetProperty to get specified property name's value
but how to get them as name list / all properties name ?
found similar issue on link below
https://groups.google.com/forum/?fromgroups#!topic/mozilla.dev.tech.js-engine/usHtJn4LR7A
Thank you very much ,sir
There are two ways to approach this. The older JS_Enumerate function or the combination of JS_NewPropertyIterator and JS_NextProperty. I would recommend the latter, because you don't have to mess around with the jsid array yourself.

Using Type-safe URLs with setMessage? (shamlet versus hamlet)

How do I use a type-safe url with setMessage?
I want to change
...
setMessage [shamlet|<span .warning>Warning! See Help.|]
...
to a message that contains a link.
From what I could gather thus far, it ought to work somehow like this
...
renderer <- getUrlRender
let html = [hamlet|<span .warning>Warning! See #
<a href=#{HelpR}> Help!|]
setMessage $ toHtml $ html renderer
...
but that code just gives me confusing error messages all over the file.
I did read the printed Yesod Book Chapter on Shakespearian Templates, but I found that it is not very explicit on the involved types. For instance what type does [hamlet|...|]| produce? Without URL-Interpolation, ghci reports t -> Markup but with URL-Interpolation inside, I just get errors.
I am further confused by all the type synonyms involved, e.g. [shamlet|...|] delivers something of type Html, while setMessage expects a Html (). I do not know how to look these up easily: Hoogle often finds nothing on the topic, while Google always finds possibly outdated versions (with examples that no longer work) - sure I get to the newest version eventually, but is there a place where I get an easy overview over these? (Can ghci list all synonyms for a type?)
Note that I actually want to produce the message in a purely functional code fragment, which is later on used by a handler. So that is why I would like to separate the URL rendering from where the hamlet is specified. Thanks for any pointer in the right direction!
I think you want to use getUrlRenderParams. Strangely enough, a related discussion came up on IRC today. Hamlet templates take a URL rendering function as their first argument, and that function must take two parameters: a type-safe URL, and a list of query string parameters. getUrlRender returns a function that doesn't take the query string parameters, which is why you need getUrlRenderParams instead.

Security Attributes when creating folder

I have the following line of code:
CreateDirectory(full_folder, attr);
Now the attr variable is of type LPSECURITY_ATRRIBUTES and is currently set to NULL. Can anyone please provide me with a list of all the keywords that are accepted by this variable. I have searched over the internet but I can't seem to find a proper list. Maybe I am not searching correctly.
Thanks :)
LPSECURITY_ATTRIBUTES doesn't take keywords, it is a pointer to a struct. Docs: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379560(v=vs.85).aspx
The useful payload of the struct is a SECURITY_DESCRIPTOR, an effectively opaque structure that you manipulate using various API functions. Docs: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379561(v=vs.85).aspx