I’m trying to capture a variable cell name in my code to use in a {% input custom.some.thing %} line of code, but am struggling to bring this input cell to life!
I’ve copied my code at the bottom of this post. As you can see, I’ve captured {{ cell_name }} as the name of the service (row title) followed by the year concerned (column title). I am then trying to call {{ cell_name }} into the input line beneath (currently illustrated as {% input custom.some.thing placeholder:cell_name %}).
When replacing this with {% input cell_name %} or {% input [cell_name] %} I lose the ability to type into the input fields. Are you able to assist with how I can treat this capture as the name of my cell whilst retaining the ability to input?
Many thanks,
Joe
{% stripnewlines %}
{% assign array_management = "Accounting Solutions|Accounting Systems Advice|Bookkeeping|Budgets and Forecasts|Consultancy and Advice|Company Secretarial|Management accounts|VAT returns" | split:"|" %}
{% assign array_years = "2018|2019|2020|2021|2022|2023|2024|2025|2026|2027|2028|2029|2030|2031|2032" | split:"|" %}
{::font size="l"}**CCH Actual Data**{:/font}
{% newline %}{% newline %}
|
{% for year in array_years %}
|{{ array_years[forloop.index0] }}
{% endfor %}
{% newline %}
|-10%-
{% for year in array_years %}
|-6%-
{% endfor %}
+
{% newline %}
{% for service in array_management %}
|{{ array_management[forloop.index0] }}
{% assign management = array_management[forloop.index0] %}
{% for year in array_years %}
{% assign year = array_year[forloop.index0] %}
{% capture cell_name %}company.custom.{{ management }}_{{ year }}{% endcapture %}
|{% input custom.some.thing placeholder:cell_name %}
{% endfor %}
{% newline %}|{% newline %}
{% endfor %}
{% endstripnewlines %}
The placeholder… Personally, I wouldn’t use it and use a general one. But never mind that.
Also, I don’t see the reason to make it a custom database variable in the company-drop. That would mean each input, no matter what year or category, is the same.
What I think you are trying to do, is make each input-object separate from each other, within the category and year. And you could use the dynamic variable for that:
custom.some.[cell_name] will be custom.some.Accounting Solutions_2019 & custom.some.Accounting Solutions_2020 and so on…
Thanks for your prompt response, and all of the pointers above!
Re: Forloop & Palceholder
Thanks for the tip! This will keep my code much tidier and easier to follow. On the same basis, I’ve cut down:
{% for service in array_management %}
|{{ array_management[forloop.index0] }}
{% assign management = array_management[forloop.index0] %}
To:
{% for service in array_management %}
|{{ service }}
And don’t worry – I won’t be keeping this! This was just to illustrate what I was expecting the cell’s name to be within the database, though thanks for the feedback
Re: Dynamic Variables
It looks like everything you’ve suggested is working as I was hoping. I had selected the company drop as this is a text document and not a reconciliation. Essentially we’re creating a document where we can push in fixed data via the API and then call this into each relevant period template by referring to i.e company.custom.some.Accounting Solutions_2019. I selected the company drop on the basis that text documents cannot have handles as I figured that this would be the only way to call on that data. Is this correct?
Let me know if there’s a better way for us to approach this, as any feedback is greatly received!
Regarding custom.some.[cell_name] - instead of capturing and using [cell_name], would the following work instead?
{% for service in array_management %}
|{{ service }}
{% for year in array_years %}
|{% input company.custom.[service].[year] %}
{% endfor %}
Thanks again for all the help & feedback - it is much appreciated!