Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
Report any technical problems you discover and discuss solutions.
  • Page:
  • 1
  • 2

TOPIC:

Variable substitution issue (?) 4 years 6 months ago #6492

  • ForteanOrg
  • ForteanOrg's Avatar Topic Author
  • Visitor
  • Visitor
Folks,
I have tried to use a variable to select an image (a logo) that should be displayed somewhere on my title page. I have set a variable "Logo" in the main page, which contains a fixed value e.g. "USER-FILES/12-user-Nottingham/media/mylogo.png". I then edit the title page and open the image dialog. and instead of filling in the (local) path to the file, I simply enter [Logo]. I have set the image size to 100 x 100, just for testing purposes.

When I run the LO, the title page appears, but without the logo. Instead some HTML code is shown, e.g.:

USER-FILES/12-user-Nottingham/media/isc2-dc.png" width="100" height="100">

.. what am I doing wrong here?

Please Inloggen or Create an account to join the conversation.

Variable substitution issue (?) 4 years 6 months ago #6493

  • JohnSmith
  • JohnSmith's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 397
  • Thank you received: 71
Hi,

Variables are a relatively new feature in Xerte and as powerful as they are, there are still some limitations as to what you can do with them and where they can be used. Well at least for now...

You can't do what you want because of the way ckeditor 'sanity-checks' the data that you enter but you can do what you want if you generate the html yourself and inject it into the page. Look at this example I have mocked up which uses dynamic variables and loads a thumbnail based on the names that you enter:



I tried with 4 variabled: name1, name2, name1img and name2img but I couldn't get the images to show. In the end I went with:

name1: default=unknown
name2: default=unknown
imgpre: default=<img width="100" height="100" src="USER-FILES/4-guest2-Nottingham/media/
imgpost: default=.png">
name1img: default=[imgpre][name1][imgpost]
name2img: default=[imgpre][name2][imgpost]

Obviously it's not perfect but it kinda works and may be about the best you will achieve but it also has it's limitations:

  • If you edit the imgpre variable then the ckeditor screws with the value and puts in some extra html tags that you need to deal with
  • The url is hardcoded so if you duplicate the LO you will have to update the 4 to another id - same with guest2 for whatever user you are logged in as

Hope that helps,

John
Attachments:
The following user(s) said Thank You: ForteanOrg

Please Inloggen or Create an account to join the conversation.

Last edit: by JohnSmith.

Variable substitution issue (?) 4 years 6 months ago #6494

  • ForteanOrg
  • ForteanOrg's Avatar Topic Author
  • Visitor
  • Visitor
Thank you for the explanation and your work-around. Given the issues I will probably not use variables for this purpose then. However, your effort is much appreciated.

Please Inloggen or Create an account to join the conversation.

Variable substitution issue (?) 4 years 6 months ago #6495

  • JohnSmith
  • JohnSmith's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 397
  • Thank you received: 71
You are welcome. I wouldn't say they are issues though - the variables were designed to be used for something very specific and this is a fringe case that wasn't part of the original spec requirements. It just so happens that they are so useful that we are finding more and more uses for them that we hadn't anticipated.

There are some additional features already committed in the develop branch that will be included in the next release - i'll mention this use case to the others and hopefully at some point in the future we can make this work as it seems like a very useful feature.
The following user(s) said Thank You: ForteanOrg

Please Inloggen or Create an account to join the conversation.

Last edit: by JohnSmith.

Variable substitution issue (?) 4 years 6 months ago #6496

  • ForteanOrg
  • ForteanOrg's Avatar Topic Author
  • Visitor
  • Visitor
Thanks again. I still can't figure out why in the particular case of using the variable in the context of a path it does not work. When I type in the path name, it just works, but if I use a variable (that contains EXACTLY the same thing I typed) it does not. Isn't ckeditor doing its thing in both cases? I'm still confused, but now on a higher level :-)

Anyway, I hope we'll get a cleaner implementation of variables in the next version of Xerte. They come in very handy indeed. I've been using them to personalise my course (the "=..." syntax), e.g.:

Enter your first name and click the button: [=Name][+submit:OK]

.. works fine.

Come to think of it: another user story that you might consider is persistent variables. I have been playing around with that a bit, and with some success. I wanted the personalisation that I just had wrought out of the learner to be persistent between sessions. So I wrote a snippet of code that I dropped in the Script container on the main LO page (the one where you define the theme). That code is run each time the LO is run. In my case the code tries to retrieve a cookie from the user's disk. If it finds it, the contents of that cookie are used to overwrite the contents of the Xerte variable. It works, but it's a bit iffy: I don't check the contents of the cookie (let alone sign it) for example, so perhaps the user might be able to fudge some Javacode in there and get it executed. And for now you can only have one persistent name, as I only store one username in one cookie. Also, to STORE the cookie, I'm relying on code that is executed on the page that follows the page that asks the user for his/her name (the next page), as I haven't figured out yet how to trigger my own code when the user presses the OK button. Currently there is a xenith event connected to that button, I'd like to insert my own code before or after that event ends, but am not sure how to do that. Yet.

I will probably work on it later on - but would welcome any suggestions :-)

Please Inloggen or Create an account to join the conversation.

Variable substitution issue (?) 4 years 6 months ago #6497

  • ForteanOrg
  • ForteanOrg's Avatar Topic Author
  • Visitor
  • Visitor
Well, I solved my problem.

The table I created had, as it is with tables, <TD> elements. So, I gave the <TD> element that contained the [=Name][+submit:OK] code an ID and connected an event to it using the Jquery .on feature.

This is the HTML (source):
<table align="left" border="0" cellpadding="1" cellspacing="1">
  <tbody>
    <tr>
      <td>If not, please enter your first name and click the button:
      </td>
      <td>[=Name]
      </td>
      <td id="Przlwkovsky">[+submit:OK]
      </td>
    </tr>
  </tbody>
</table>

And this is the Javascript to create the onclick event, using Jquery. Paste it in a "Script" container that you can add to the page (or add it to any already existing code you may have):
$( "#Przlwkovsky").on('click',function(){
  // code to store cookie goes here, for demonstration purpose just an alert now:
  alert("Saving your data..")
});

Now, if he user clicks the button the event attached tot the button will fire and the usual Xerte xenith stuff will be done. But because the button is inside the <TD> element, that is clicked too and the event attached to it is also fired. Solved!

You can, methinks, connect other events to some <DIV> (with an ID) you can create in your page. I tried the unload event but that is not triggered if you leave the subpage. Mm..

Please Inloggen or Create an account to join the conversation.

Last edit: by ForteanOrg. Reason: Typo
  • Page:
  • 1
  • 2
Moderators: ronmjultenJohnSmith
Time to create page: 0.071 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search