I've been using templates in Cro (documented at https://cro.services/docs/reference/cro-webapp-template), and have enjoyed that there are subs in them.
I currently have a 'main' template, and some reports, let's say report1, report2, and report3.
Let's say that, from report3, I want to include an array of report1.
Now, let's say that the reports each have the following subs:
init: Some Javascript initialisation code (that should only be included once, no matter how many instances of the report are used)
HTML: Some HTML code that should be included for each instance of the report (with a few parameters to differentiate it, but that, due to the restriction of the Javascript framework, may not contain any <script>
or <style>
tags
data: A snippet of Javascript that again has to be repeated for each time the report is included
Currently I have each of the above in a separate sub in the template.
Redeclaration of symbol '&__TEMPLATE_SUB__report-initial'.
While I can pass a report name (eg. "report1") to the main template, what I'm lacking is a way to have the main template call the subs on the report name that has been passed in, since there may be multiple reports involved.
What would be ideal is if I could somehow create a "report" class that inherits from the template, and pass instances of the template class into the main report, and then call the subs as methods on the report class. However, I've been unable to figure out a way to do this.
I can see three likely options here:
Any help anyone can provide would be appreciated.
Thanks!
Edit: I think a macro that can have multiple (named) "bodies" would solve the problem.
What is a CRO program? A CRO program, also known as a CRO plan, is a digital marketing strategy that businesses develop for improving the conversion rate of their website or app. CRO programs involve analyzing an entire website to find obstacles to conversion and then optimizing web pages to improve conversion.
Let's get started! Access your free CRO action plan. Make a copy of the plan and start learning about your users to increase your conversion rate. It's a shared Google doc — we won't ask for your email! The 3 steps to increase conversion rate: If you want to convert your traffic, you need to understand why people are reaching your website .
Make yourself a copy by clicking on 'Make a copy' below, and when you get on the document, clicking on File > Make a copy. Let's get started! Access your free CRO action plan. Make a copy of the plan and start learning about your users to increase your conversion rate. It's a shared Google doc — we won't ask for your email!
When using objects as a parameter in Azure Resource Manager templates you may want to include them in a copy loop, so here is an example that uses them in that way: This approach becomes very useful when combined with the serial copy loop, particularly for deploying child resources.
my initial response to your question is "please can you provide a minimal reproducible example of your code so that we can get a deeper view of the context and have something that we can experiment with"
my current understanding of what you need is "to use raku style classes & objects (with callbacks) in a Cro template setting" - and that the standard ways of doing this such as associative access to a nested topic variable are too limited
in itself, this is not necessarily a weakness of raku / Cro in that the power of a template slang needs to be limited to avoid potential security issues and, as with most template systems, is a bit more prosaic than a full blown coding language
my guess is that Cro template-parts which can chunk up web parts and steps in and out of the (real raku) root block can, depending on how you chunk things up, handle the report data structure that you describe - have you tried this?
if this is still not tenable, there are a couple of ways to expand the options such as dependency injection and route handlers
It looks like &__TEMPLATE_SUB__report1-initial
is a global that is redeclared when you import report1
into report3
. May I suggest to try and use template fragments instead of the whole template?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With