Docxtemplater - Newlines between loop iterations - docxtemplater

TLDR - how do I use either a custom parser function or modify the loop module to it'll add a newline after each iteration?
Long story:
I'm using old templates that used to be rendered with some MS tools, now trying to render them with docxtemplater. Main requirement is to not modify the templates. Use them as they are, and be able to render documents as identical as possible to that MS tool.
Here's what a loop looks like in one of the templates:
«TableStart:MortgageInfo»« MortgageInfo_Name»
« MortgageInfo_MortgageStreet»
«CityStateZip»«TableEnd:MortgageInfo»
I used custom delimiters for « and » and created a custom loop module to handle the custom TableStart: and TableEnd: format.
There is no linebreak between «CityStateZip» and «TableEnd:MortgageInfo» so the 2nd item is rendered immediately after the 1st without a linebreak.
Anybody has any idea how I add this missing linebreak? Please bare in mind - no modification to the template is allowed...

Related

Yahoo Pipes - Build an RSS-URL using specific parameters pulled from another RSS feed's content

The main Data Type used by Yahoo Pipes is the [Item], which is RSS feed content. I want to take an RSS's content or sub-element, make it into [Text] (or a number might work), and then use it as an INPUT into a [Module] to build a RSS-URL with specific parameters. I will then use the new RSS-URL to pull more content.
Could possibly use the [URL Builder Module] or some work-around.
The key here is using "dynamic" data from an RSS feed (not user input, or a static data), and getting that data into a Data Type that is compatible (and/or accessible) as an INPUT into a module.
It seems like a vital functionality, but I cannot figure it out. I have tried many, many work-around attempts, with no success.
The Specific API and Methods (if you are interested)
Using the LastFM API.
1st Method: user.getWeeklyChartList. Then pick the "from" (start) and "to" (end) Unix timestamps from 1 year-ago-today.
2nd Method: user.getWeeklyAlbumChart using those specific (and "dynamic") timestamps to pull my top albums for that week.
tl;dr. Build an RSS-URL using specific parameters from another RSS feed's content.
I think I may have figured it out. I doubt it is the best way, but it works. The problem was the module I needed to use didn't have and input node. But the Loop module has an input node, so if I embed the URL builder into the Loop module I can then access sub-element content from the 1st feed to use as parameters to build the URL for the 2nd feed! Then I can just scrap all the extra stuff generated by the Loop, by using Truncate.

Is it possible to intermix Modular templating and legacy VBScript CT?

In particular, the case I have in mind is this:
##RenderComponentPresentation(Component, "<vbs-legacy-ct-tcm-uri>")##
The problem I'm having is that in my case VBS code breaks when it tries to access component fields, giving "Error 13 Type mismatch ..".
(So, if I were to give the answer, I'd say: "Partially, of no practical use")
EDIT
The DWT above is from another CT, so effectively it's a rendering of component link, that's why parameterless overload as per Nuno's suggestion won't work unfortunately. BTW, the following lines inside VBS don't break and give correct values:
WriteOut Component.ID
WriteOut Component.Schema.Title
EDIT 2
Dominic was absolutely wright: it's a missing dependencies.
A bit more insight to make this info generally useful:
Suppose, the original CT looked like this ("VBScript [Legacy]" type):
[%
Call RenderComponent(Component)
%]
This CT was meant to be called from a PT, also VBS-based. That PT had a big chunk of "#include" statements in the beginning.
Now the story changes: the same CT is being called from another, DWT-based, CT. Obviously (thanks you all for your invaluable help!), dependencies are now not being included anywhere.
The solution to make original CT working again is to explicitly hand-pick and include all necessary VBS TBBs, so the original CT becomes:
[%
#include "tcm:<uri-of-vbs-tbb>"
Call RenderComponent(Component)
%]
Yes - it's perfectly possible to mix and match legacy and modular templates. Perhaps obviously, you can't mix and match template building blocks between the two techniques.
In VBScript "Error 13 Type mismatch" is sometimes used as a secret code that really means "I don't recognise the name of one of your variables, (including the names of Functions and Subs)" In the VBScript templating engine, variables from the page template could be in scope in your component template; it was very common, for example, to put the #includes in the PT so they could be used by the CT. My guess is that your component template is trying to use such a Function, and not finding it.
I know that you can render a Modular Page Template with VBScript Component Presentations, and also a VbScript page template can render a modular Component Template.
Your error is possibly due to something else? Have you tried just using the regular ##RenderComponentPresentation()## call without specifying which template?
The Page Template can render Compound Templates of different flavors - for example Razor, VBS, or XSLT.
The problem comes from the TBBs included in the Templates. Often the Razor templates will need to call functions that only exist in VBScript. So, the starting point when migrating templates is always to start with the helper functions and utility libraries. Then migrate the most generic PT / CT you have to the new format (Razor, XSLT, DWT, etc). This provides a nice basis to migrate the rest of the Templates as you have time to the new format.

using GetText to translate wordpress using variables instead of default language

I want to make my wordpress theme translation ready.
I was thinking to use GetText function within wordpress like: _e('sometext')
But I was thinking, what happens when I want to change default English 'sometext', I have to go to different php files (where I used _e('sometext')) find all instances and replace it with _e('sometext2') ?
Or in my PO file I just make English column, use _e('sometext') in wp php files, but in PO file specify 'sometext2'?
I would use something similar to the concept of constants, e.g:
<?php _e('TXT_ABOUT_INTO'); ?>
TXT_ABOUT_INTO will be like a placeholder, and you will need to create a translation file for English as well as for other languages.
Yes, if you decided to replace "sometext" with "some other text" you would need to go through the templates wherever _e('sometext') appeared and replace it with _e('some other text').
But... imagine you did not wrap your text in gettext calls. Then you would have to go through your templates to replace "sometext" with "some other text".
Not a lot of difference, and if you were to do a global find & replace you'd be much less likely to accidently change something if your search term was "_e('sometext')" than "sometext".
I've followed your example, but you should be including the text domain when you wrap the text, e.g. _e('sometext', 'my-theme')

How to restrict text length of a field while in WordPress editor?

I would like to restrict the fields while creating a new post in WordPress. For the title, it should not exceed 40 characters. For the content, it should not exceed 400 characters. If these maximum values are exceeded, I would like to show an error message and not let the user continue. How do I do that in WordPress?
You should be able to use wordpress filters to modify the code that gets outputted when the editor is called. Essentially you would want to use it to insert some javascript and an extra div tag to display your error, then just read the contents of the "editorcontainer" id and show the error once it reaches a certain character limit.
I don't have the time at the moment to write a case example, but depending on your skill level, the functions you are looking for are:
apply_filters("the_editor", "customfunction_limitarea");
Where customfunction_limit area is your created function to insert the javascript. You can see how the_editor is currently called and how the default filters are applied in "wp-includes\general-template.php" on line 1822. The default looks like this:
$the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
I would try modifying that statement by placing a new filter in a functions.php file located in your themes directory, that way you don't have to worry about it getting over-written during an update. Otherwise, if you absolutely have to edit the wordpress core (generally a no-no), general_template.php would be the place to do it I think.
Essentially just read up on wordpress filters a little bit (be warned there's not a ton of documentation or examples available for it other than the basic stuff), and that should provide everything you need. The input verification end is easy enough to find scripts, just google jquery post limiting. Something like this might be exactly what your looking for:
http://swiki.fromdev.com/2010/02/jquery-maximum-limit-texttextarea-with.html

Insert programming code in a Lyx document

What is the best way of inserting python/C++ code in a Lyx document? The code is small examples less than 20 lines.
My Lyx document is using the Book document class.
Orjanp
I prefer to insert the listings as a child document, so the code is grabbed directly from a file that you can further edit and keep updated (you avoid to duplicate an information and maintenance is a lot easier).
To do this in Lyx:
Insert->File->Child document
Then in the window that will appear change the type to program listing and configure it as you need, for example you could want to enter the parameter language=Python (you can type a ? to view all the parameters).
A set of parameters I usually use is:
breaklines=true //--> breaks lines to margin
captionpos=b //--> caption at the bottom of the listing (default is "t")
frame=tb //--> frame at the top and at the bottom of the listing
language=Python //--> syntax highlighting for python
There should be an Insert -> Program Listing option. That uses listings Latex package, so you should have that installed. The support seems to have been added in Lyx 1.5, and from their screenshot, it seems it gives you a lot of customization options.
The insert->Program Listing feature works great. I just want to add that if you are on Mac, and try to directly paste, using command+V or right-click+paste, a block of code into the program listing, the whitespace will not be preserved, and you have to manually insert the whitespace by typing tabs, returns, etc.
A very easy way to get around this is is to paste using shift+command+V. This preserves all the whitespace of your original source code.

Resources