dsusak
I'm new here

Replace placeholders in text

Hi everyone,

I'm quite new to FirstSpirit and it's API and not sure how could/should we solve the following Problem:

In our project we have a few statistical data, which are used by our editors on different pages. (e.g. number of employees in the company, number of open job position, number of customers...)

Currently these numbers are entered manually (hard-coded), on all pages where needed. Since these number change quite often, editors have to change them every time, in many different places.

Our idea is to create a separate table in datasouces in SiteArchitect, where these number would be stored, together with the descriptive placholder. (e.g. [employeeCount], [jobCount], [customerCount])

Afterwards, editors would replace the hard-coded numbers with these placholders.

The question is, what would be the best option to implement the replacement of these placeholders with the real numbers, from the defined datasource?

Our first attempt was to create a format template, which would do the replacement, and would be later included in all section templates where needed, via CMS_RENDER.

Although this works, our project is really big, and we have hundreds of templates, which should be updated with CMS_RENDER instruction.

Is there any other possibility to do this, possibly in fewer than hundred places?

Can something before/during the generation process be done, with FirstSpirit API and deployed as FS module for example?

Any other suggestion would be much appreciated.

Thanks!

Regards,

Dragan

0 Kudos
2 Replies
bIT_sosswald
Returning Responder

Hi Dragan,

I have a few ideas in my mind currently. Depending on your requirements which are not totally clear to me.

Are those values always the same (also the same combination)? Or can the editors decide which values from a big list of possible values they want to display on a page? Can new values be added in the future? Etc.

  1. Use of DataSources
    When using DataSources I would implement something like a DataSource-Link to select which data source entry should be displayed. (You can directly select a DataSource entry as a link target like you do it with pages or files.)
    Now the section / page template would use this link to access the DataSource entry, extract the values and also the labels like “Number of employees” and put them in the generated HTML. This can be done using a render template to only have this code once.

    Positive: Flexible, you can add additional values in the future
    Negative: You must select / reference the DataSource entry each time

  2. Use of global data
    If the amount of those numbers is fixed and no (or very less) new stuff is added in the future you could use a GCA-Page to maintain this data as global data. Depending on the requirements you now can just put that data into the HTML or provide the editors with select-option to select which of the data should be shown on the page.

    Positive: No DataSources are needed, the editors must not select a specific DataSource entry
    Negative: Less flexible when new stuff should be added. (Implementation effort needed.)

  3. Changing the generated HTML afterwards.
    You had the idea already and yes this is possible. FirstSpirit generates into a local staging directory. So it would be possible to just print some placeholders in the HTML, parse all HTML files after generation and replace the placeholders. This could be done in a central module which is started by an executable in your generation schedule.

    Positive: You can do it with Java and the editors don’t have to do anything.
    Negative: Preview will differ from the live website, you have a dependency between your templates and the module (if a template developer is messing things up your module will break and you will have a broken website.)

So as always it depends.  

Greetings Sandro

0 Kudos
Peter_Jodeleit
Crownpeak employee

Hi Dragan,

Sandros provided already a good list of options. I want to add another one:

4. Replace placeholders in template code

You can replace the placeholders from within the template. The cleanest way would to provide some central function for the replacement, but as a quick start you can do something like $CMS_VALUE(my_text_input_component.replaceAll("${number_of_open_jobs}", 42))$ in your template code.

Regards,

Peter

Peter
0 Kudos