In case you ever need it here's a safe substring t...
# advancedpdf
c
In case you ever need it here's a safe substring that guards against out of bounds usages (NS really hates doing s[0..30] when the string is only 20)
Copy code
<#function safe_substring str start end>
		<#if !str??>
			<#return "">
		</#if>

		<#assign s = str?string>
		<#assign len = s?length>

		<#assign start = start?number>
		<#assign stop = (end?number < len)?then(end?number - 1, len - 1)>

		<#return s[start..stop]>
	</#function>
💯 2
thankyou 1
c
Nice to see someone actually using the functions and hopefully macros in advancedpdf
c
Our old template by our implementation partner just copied and pasted the vendor/customer voucher details.. this was a nice cleanup to remove the duplicate stuff.
c
Yep I do not doubt that. Using these functions/macros cut down a ton of code (or can)
c
Do you know of a way to expose record.credit|apply|deposit as one list instead of having the same blocks copied with updated field references?
c
A generic function that you can specify the sublist/field ids may work. I don't think its bad in a case like this to have a function per even though its similar. For advanced pdf, i'll take the readability over something fancy any day.