0

Use Case: I maintain a simple site for a small orchestra. Originally written in Joomla 2010, updated to Joomla 3 in 2016 and now updating to Joomla 4/5. Each concert, the items, conductor, soloists etc. are entered in the Administrator backend using my component com_concert which stores the data in my own tables in the database. The site part of the component enables sorting and filtering for displaying past events. I have completed the upgrade of the administrator component for inputting the data and the site part for displaying the concert history. In the past, someone has edited the front article page manually with the latest concert details, and then added those same details again into the long term database records in the backend. All I want to do is to insert the various latest concert details to the front article page so eliminating the need for doubling the task of entering the data. The front page needs to be able to be edited manually because for some concerts different images and extra text are needed. I think this need probably rules out the use of a form for displaying the latest concert details.

Solutions tried:

  1. It looked to me as if using Custom Fields was the right way to go. (see https://magazine.joomla.org/all-issues/april-2020/custom-fields-episode-4-a-step-by-step-tutorial) I have succeeded in adding custom fields to the Article and they appear in front of the page text correctly. But I want them to appear in various places on the page, within bits of text or next to an image, for example. Currently, the relevant text is simply typed into cells in a table for display purposes. Unfortunately, when I set the display option to “Do not automatically display”, they don't appear at all. From other postings, I thought the solution would be simply to insert the tags {field 1} {field 7} etc. to the locations I wanted, but all I get is the text "{field 1}" appearing, untranslated into a field value. Having tried many alternative placings of the tags, I decided to try something else. Sourcerer.
  2. Having installed Sourcerer, I can get the tags {Source} code.....{/Source} to work with a simple <?php echo statement. But to put the complete sql code into an article that needs to be editable by an unqualified person looks like a recipe for disaster, and I decided the only acceptable way of doing this within Sourcerer would be to make a simple call to a function within my site component. But after trying as many forms of "include" and function calls as I could think of, I cannot get anything other than an error message saying it cannot find the relevant class.

Question: Can anyone tell me either : (a)(my preferred solution) the correct syntax (preferably with an example)for placing a custom field in some text in an article? or (b) (fallback solution) the correct syntax within Sourcerer to call, say, a function in a helper file from my com_concert component? or, from the use case description, (c) a better way of doing it!

2
  • Wordpress has a feature called "shortcodes" which enables editors to embed links to fields by placing "{field 1}" etc within the article text. You can easily write a content plugin which does the same for Joomla by triggering on onContentPrepare, looking for "{...}" within the text and replacing these fields with data from your database table. Do you think that might be a viable solution? Commented Jan 7 at 19:57
  • Robbie, just spotted your very prompt answer. Your suggestion looks as if it might be a viable solution, and I will try it. But I'm surprised that the functionality, which some threads seem to suggest already exists in joomla , simply isn't working.
    – DerekE
    Commented Jan 8 at 17:59

1 Answer 1

0
  1. I discovered the answer to the {field 1} not showing field value problem when I did a Joomla upgrade and found that the content_fields plugin was missing. Using "Discover" and then enabling it brought the Joomla functionality to life, I'm happy to say. There is no special syntax, it is quite sufficient to include {field 1} in the middle of some text.
  2. Sourcerer seems to work OK, but I don't now need it for my solution.
  3. Robbie's suggestion of writing my own plugin seems like a good architectural solution though, with perhaps more control and flexibility than using custom fields.

I am in the process of implementing it and will then decide which solution to use in practice. The key determinant will be which solution best prevents unskilled users from messing up the automatically generated information when editing the articles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.