I've been working on something where I need to bui...
# lucee
d
I've been working on something where I need to build some large text blocks. I've always wanted a way to basically just create a block of text and have it interpretted as text. Similar to the way templates work in JS using the backtick, where you can have carriage lines and don't have to worry about escaping quotes, etc. The closest thing I've come up with in Lucee is something like the following, but it looks at feels very hacky to me:
Copy code
savecontent variable="text" {
Hello world! My name is Dan!
Copy code
}
It's not great looking, but it works. I wish I could do `text = ``` ... ```;` or
text =
...
;
instead. Any better tricks for creating large blocks of formatted text inside a CFC?
a
Poss not helpful, but I think the question is begging. I'm screwing up my nose at the premise of "creating large blocks of formatted text inside a CFC"
HOwever if I really needed to do it, and couldn't just quit the job that was requiring me to do it ( 😉 ), I'd do it how you suggested.
(so there you go... an unhelpful answer, but also a helpful one)
(I'd chuck the text in its own file, and read it in within the CFC)
(or I'd have a CFC that's job is to load formatted text from file into variable and return it, more like, rather than have that logic in the CFC you're consuming it with)
but for inline stuff... exactly how you suggested. I don't think it's so bad, and almost makes me think "actually a reasonable use of "tag" islands"
👍 1
d
I'm playing around with some GPT integration. In testing, I'm generally developing large prompt strings to instruct the conversation API to return what I want. It's easier to do if I can just type text. I wouldn't release the code this way, but while trying to play around with it, having everything as a long block of text is convienent.
✅ 1
I would also argue, that it could be helpful to have a mechanism for this when doing things like creating SQL statements as well.
z
er, that already works with query
d
@zackster, Technically, I know that the triple backtick is a tag island and I can <cfquery /> in there (or use the "text" example above to capture the output), but what I really meant is it would be great to do something like:
Copy code
queryExecute(`
select
  *
from
  Table
where
   Column1 = 'A'
and
   Column2 = 'Why print "Hello World"'
`);
Or something to that affect.
z
tag islands means you can use cfqueryparams
normal quotes across multiple lines works
d
I know that, but then you have to be careful about escaping quotes. I was just looking for an easy to way to interpret text as a string and not need to worry about escaping common characters that appear in text (like quotes).
i
Java 15 has text blocks using triple double-quotes """ some test 'here' """. Maybe something like that comes in Lucee/ACF at some point?
d
Another place this would be handy is in unit tests. There are times when a test might be inputting a block of text. When I'm writing a new test for a bug, I might need to copy and paste the bad input. It would be great to do this in a way that didn't require me to change the output. For extremely large chunks of text, I use an external file, but often having things inline where everything is in the test is helpful.