[Solved] How to style text and add images to Content Area of field?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: How to style text and add images to Content Area of field?
@Bogs,
Opps! Yes, your code works. It just doesn't answer what I'm trying to do. I don't ever want the "raw" html code to show. I only want the styled result to show. I want the styled result to show no matter how many times I go from one card to another.
I am sending a sample so that you can see what I'm trying to do. The problem is that it only works one time. The second time it strips the text of the tags and displays, more or less, a standard LC text without styling.
TIA
-Rachel
Opps! Yes, your code works. It just doesn't answer what I'm trying to do. I don't ever want the "raw" html code to show. I only want the styled result to show. I want the styled result to show no matter how many times I go from one card to another.
I am sending a sample so that you can see what I'm trying to do. The problem is that it only works one time. The second time it strips the text of the tags and displays, more or less, a standard LC text without styling.
TIA
-Rachel
May I never be cured of my curiosity!
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to style text and add images to Content Area of field?
It sounds like you are creating (or retrieving) some htmlText on one card and you want it to show in another one when the card opens. Is that right?
If so, you can do it from card 1 if you want:
If instead you want to store the html somewhere and show it when card 2 opens later, put the retrieved html into a global variable (I don't like those but they work) or a custom property. Let's say you store it in a custom property:
Then when card 2 opens:
There is no specific "refresh" in LC but anything a script does to change the card is instantly displayed so it isn't needed very often.
Also, you can change almost anything from anywhere without actually being on that card; text in fields, appearance of controls, even scripts, as long as you use a full reference to the target object. The object can even be in a different stack.
If so, you can do it from card 1 if you want:
Code: Select all
on updateHTML
-- retrieve the html here somehow, put it into a variable
set the htmlText of fld "somefield" of card 2 to tVariable
end updateHTML
Code: Select all
on updateHTML -- still on card 1
-- retrieve the html here somehow, put it into a variable
set the htmlVar of card 2 to tVariable -- creates a custom property of card 2 named "htmlVar"
end updateHTML
Code: Select all
on preOpenCard -- on card 2
set the htmltext of fld "somefield" to the htmlVar of this card
end preOpenCard
Also, you can change almost anything from anywhere without actually being on that card; text in fields, appearance of controls, even scripts, as long as you use a full reference to the target object. The object can even be in a different stack.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to style text and add images to Content Area of field?
I took a look at your stack. This line only retrieves the plain text:
You haven't specified a text format, so it's getting the default which is plain text. If you want the htmltext, change the line to explicitly get what you want:
It seems a little silly to get the html and then put it back, but I'm assuming you have bigger plans in mind.
Code: Select all
put field "Field" into tTemp
Code: Select all
put the htmltext of field "Field" into tTemp
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How to style text and add images to Content Area of field?
AHA!
Must have overseen this in your earlier postings!
You do this:
The first time you open the card, LC takes the RAW source code text of that field and does the appropriate formatting to the same field (this is the key, see below).
OK, so far, so good.
But next time you visit that card
-> put field "Field" into tTemp
the field and tTemp does now contain the unformatted TEXT of that field,
because the field does NOT contain the above mentioned RAW html source anymore.
And you are right, I think you are thinking way too far.
Why not just save your stack with the already nicely formatted field?
I really do not see any meaning in what your are currently doing "on preopencard", sorry
Best
Klaus
Must have overseen this in your earlier postings!
You do this:
Code: Select all
on preopenCard
put field "Field" into tTemp
set the htmlText of field "Field" to tTemp
end preopenCard
OK, so far, so good.
But next time you visit that card
-> put field "Field" into tTemp
the field and tTemp does now contain the unformatted TEXT of that field,
because the field does NOT contain the above mentioned RAW html source anymore.
And you are right, I think you are thinking way too far.
Why not just save your stack with the already nicely formatted field?
I really do not see any meaning in what your are currently doing "on preopencard", sorry
Best
Klaus
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: How to style text and add images to Content Area of field?
Thanks to everyone for your thought provoking replies.
I'll study your responses and see what I can do.
-Rachel
I'll study your responses and see what I can do.
-Rachel
May I never be cured of my curiosity!
Re: How to style text and add images to Content Area of field?
I took a look at the stack you posted. What I made of it was that you had put this text into the field initially -
.. and you want that to display like this every time the card opens - .. and you want it to look that way every time you come to the card. First, I want to point out what Jacque was saying, you don't need code in the program to do this. Just to quickly convert your raw html to actual html displayed in the field, I did this in the message box - .. then commented out all the code referring to it. That field is now set to the htmlText, and will display that way no matter how many times you open/close/navigate away/to it. In the comments are the notes from this thread. Hope this helps out a bit more
Code: Select all
<h3 >Refrigerator Snacking?</h3>
<ul>
<li>Cheese with home made bread</li>
<li>Leftovers </li>
<li>Grapes </li>
<li>What ever you like and can find there.</li>
<li>Hey, when you are hungry, you are <p><b>HUNGRY!</b></p><li/>
</ul>
.. and you want that to display like this every time the card opens - .. and you want it to look that way every time you come to the card. First, I want to point out what Jacque was saying, you don't need code in the program to do this. Just to quickly convert your raw html to actual html displayed in the field, I did this in the message box - .. then commented out all the code referring to it. That field is now set to the htmlText, and will display that way no matter how many times you open/close/navigate away/to it. In the comments are the notes from this thread. Hope this helps out a bit more
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: How to style text and add images to Content Area of field?
@Bogs.
Are you superman in disguise?
That code snip is EXACTLY what I am trying to do. The days I spent on that and the solution was SO easy. You only convert ONE time. Sheesh! See what I mean about my not being a great coder. Everything I do takes me 100 times longer than most others.
I was planning on tackling HTMLtext again today, but I sure wasn't looking forward to it. Finding your sample was a major relief.
Jacque's solution made good sense but I haven't studied creating properties yet so I was thinking I'd need to do that first. Plus, even with properties, I'd still have been trying to convert, save, and convert. (endless loop)
Properties look so KOOL. I read a little about them last night, they will last beyond what a global variable lasts and will save the app's state. Probably a great use for the famous "To Do" app.
The only thing that keeps me going with LC is this forum and all of the people who make it so friendly.
Now off I go to see what other trouble I can manage to find in LiveCode.
Thank you, thank you, thank you. MAJOR joy.
-Rachel
Are you superman in disguise?
That code snip is EXACTLY what I am trying to do. The days I spent on that and the solution was SO easy. You only convert ONE time. Sheesh! See what I mean about my not being a great coder. Everything I do takes me 100 times longer than most others.
I was planning on tackling HTMLtext again today, but I sure wasn't looking forward to it. Finding your sample was a major relief.
Jacque's solution made good sense but I haven't studied creating properties yet so I was thinking I'd need to do that first. Plus, even with properties, I'd still have been trying to convert, save, and convert. (endless loop)
Properties look so KOOL. I read a little about them last night, they will last beyond what a global variable lasts and will save the app's state. Probably a great use for the famous "To Do" app.
The only thing that keeps me going with LC is this forum and all of the people who make it so friendly.
Now off I go to see what other trouble I can manage to find in LiveCode.
Thank you, thank you, thank you. MAJOR joy.
-Rachel
May I never be cured of my curiosity!
Re: How to style text and add images to Content Area of field?
Not that we have been trying to explain this on the first page of this thread a couple of times...
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: How to style text and add images to Content Area of field?
Klaus,
Sometimes, "a picture is worth a thousand words"!
Thanks for your patience.
PS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
-Rachel
Sometimes, "a picture is worth a thousand words"!
Thanks for your patience.
PS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
-Rachel
May I never be cured of my curiosity!
Re: How to style text and add images to Content Area of field?
yep, sometimes.
Oh, good question, although I'm an admin, I have no idea.ValiantCuriosity wrote: ↑Sat Mar 09, 2019 7:12 pmPS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
But this is really not neccessary.
Re: How to style text and add images to Content Area of field? [Solved]
Since it took me a ^10 the amount of times it did you, I think you'll be fineValiantCuriosity wrote: ↑Sat Mar 09, 2019 6:28 pmThat code snip is EXACTLY what I am trying to do. The days I spent on that and the solution was SO easy. You only convert ONE time. Sheesh! See what I mean about my not being a great coder. Everything I do takes me 100 times longer than most others.
(Klaus and Jacque did say it first, me, I just take your request at face value and put what I think would work for that situation. Superman, or super silly, tough call )
Properties are very simple to make, set, and get, and as was also pointed out earlier in the thread, used a lot in place of almost anything else.
As simple as going to your first post in the topic, and typing [Solved] in any way you wish.ValiantCuriosity wrote: ↑Sat Mar 09, 2019 7:12 pmPS. How do I mark this topic as solved? I have seen that done, but can't find a "how to" in the FAQs.
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: [Solved] How to style text and add images to Content Area of field?
@Bogs!
You are "THE Man" of the hour. I missed that one. Now, maybe, this whole long and painful journey with HTMLtext will save some other poor wandering soul.
-Rachel
You are "THE Man" of the hour. I missed that one. Now, maybe, this whole long and painful journey with HTMLtext will save some other poor wandering soul.
-Rachel
May I never be cured of my curiosity!
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: [Solved] How to style text and add images to Content Area of field?
I'm a one trick pony and LC is really the only language I know. But I did try dabbling in a couple of others way back when, and I found there is much more to it than just learning the terms and syntax. That's actually the easier part. You also have to know how the language interacts with the environment, and that varies. Learning that is as big a job as learning the rest of it.
If you're coming from a web based environment, you're used to recreating every page from scratch on every reload. That's not the behavior LC uses, where changes are permanent for the session, and if the stack is saved, permanent forever. It's stuff like this that can sometimes be a bigger hurdle than just figuring out what syntax to use.
You'll get there, but the first few weeks can be frustrating.
If you're coming from a web based environment, you're used to recreating every page from scratch on every reload. That's not the behavior LC uses, where changes are permanent for the session, and if the stack is saved, permanent forever. It's stuff like this that can sometimes be a bigger hurdle than just figuring out what syntax to use.
You'll get there, but the first few weeks can be frustrating.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 128
- Joined: Thu Jun 30, 2016 3:08 am
Re: [Solved] How to style text and add images to Content Area of field?
@Bogs,
imageSource is "the bee's knees"! Thanks for pointing it out. It allows me to insert the photos into my descriptive text in a scrolling field. Happy Dancing here.
Hey, I can even style the images to be centered or right aligned. BOY, did this all take some study. This the simplest part of a little test rewrite for one of my more basic apps. At first, I thought LC just would not do what I needed. Looks like there is a way!
It doesn't seem to flow the text around the image, but I can make due with what I've got for now.
Thanks to all who responded to this rather lengthy forum question.
-Rachel
imageSource is "the bee's knees"! Thanks for pointing it out. It allows me to insert the photos into my descriptive text in a scrolling field. Happy Dancing here.
Hey, I can even style the images to be centered or right aligned. BOY, did this all take some study. This the simplest part of a little test rewrite for one of my more basic apps. At first, I thought LC just would not do what I needed. Looks like there is a way!
It doesn't seem to flow the text around the image, but I can make due with what I've got for now.
Thanks to all who responded to this rather lengthy forum question.
-Rachel
May I never be cured of my curiosity!
Re: [Solved] How to style text and add images to Content Area of field?
We knew you could do it
No, imageSource will certainly not do that. What it is doing is taking one character in the field, and putting an image in its place, that is it. Think of it as a quick cheat (but maybe not the best cheat ).ValiantCuriosity wrote: ↑Wed Apr 03, 2019 10:10 pmIt doesn't seem to flow the text around the image, but I can make due with what I've got for now.