Code snippet entries

So i have need to ad a code snippet..
i think there are three options

  1. a datatype to allow users to add some code say to integrate with a third party. so they can change the code by updating it directly.
    a- and use a richtexteditor
    b- mark down editor

2 do it with a switch that does it all in code .. so if code changes its deploy

ie (PseudoCode
if (showTrue)
{
show fixed code snippet ( or partial)
}

So I guess your question is what option to use? Perhaps you can tell a little bit more about what you want to do exactly and what the snippit is for.

So in my case it’s to add trust pilot code
A third party snippet

It’s basically an option to dump code in and I’m happy with that but it got me thinking what does give kind say and do

Ok, I get the idea.

I think the solution depends on the budget, time, how often it changes and the skill level of the editor(s).

By default, I prefer to be in control as a developer. Editors can mess things up. But making it more robust usually takes more time, so that’s a trade off.

  • The easiest is to just dump some code in a text area (I prefer a text area, a rte can strip stuff). It’s by far the easiest, but editors can mess things up and if you literally insert what’s in the text area in your HTML it might even break the frontend worst case. So editors need to know what they are doing.
  • A step more robust is for you to add the code to the page and only enter something like a unique identifier for trust pilot into the backoffice. You can even do some basic validation on it. Also, when the code changes, you don’t need to update the code in multiple content fields. Editors cannot break the frontend this way. The only downsite is that editors need to know what the identifier is and where to get it.
  • Ofcourse you can even make it nicer at the cost of much more time.

So all in all, I would say option 2 is the best for you.

Hi Ravi,

The way I do it is using a custom text editor which displays some code highlighting however you could do the same with a textarea. I wouldnt use RTE because this strips out code.

I then have an option to either display or run the code:

1 Like

@LuukPeters gents thanks for the input..

It’s very much along the lines of what I was thinking.. it’s just one of those things that I haven’t had to put much thought into.. and just getting a feel for what other ideas are out there..

And it’s as you say very much budget constrained.. .

It’s one of those fields .. not meant for an ordinary punter.user field..

But then this is a temporary thing,to be superseded most likely ina few weeks
So finding a robust solution whch has a quick turnaround has sort of been key

Ah well it’s not perfect but I’m okay with that

Hi Ravi :waving_hand:

Just wanted to mention that Lee’s Contentment package includes a Code Editor property editor which is perfect for this (requires you to have Contentment installed, I know, but we use it for so many things that it’s a default install for us :grin:)

/Chriztian

5 Likes

@greystate as ever.. you are a gem..

Thanks for the reminder.. I’m not sure why I didn’t think of contentment (@leekelleher will be furious, maybe even point break furious (inside joke))

1 Like