Parametrize snippets
-
I am developing snippets for my website to display information about objects stored a MySQL database. I would like a single snippet to display a record from my database based on the record’s ID (primary key) field. For various reasons, each of the objects in the database has its own page on my site, so I need to be able to reuse the snippet and pass the ID to it somehow.
I used to have PHP Snippets, which supports parameter values in the shortcode. I’m moving to PHP Code now, and am desperately seeking a solution.
Of course, I could work around the issue by creating tiny snippets for each ID, that set the ID in the global array that PHP Code supports. In that way, I could insert the appropriate ID-setting snippet on each page and solve my issue that way.
However, that’s rather an ugly workaround. Is there a better way to pass a parameter into a snippet?
- The topic ‘Parametrize snippets’ is closed to new replies.