How do I make relative hyperlinks rather than absolute hyperlinks?
I am creating a master course that we will Restore each time a new section of the class starts. Within the course, I want to make links to various sections of the course so students don't have to do all of their navigation through the Activities block.
I understand how to link to Resources I've uploaded but can't figure out how to make relative hyperlinks to things that Moodle creates during the restore. For example, I may want to create a link to a specific discussion forum from within assignment instructions I give students. Absolute hyperlinks take students back to the Master course and that just won't do. I need to understand how to make a relative hyperlink so the links take students to the appropriate discussion forum within their instance of the course. This needs to work without my manual intervention each time the course is restored for the next batch of students.
I looked in the Teacher documentation and couldn't find the answer to this question. I even tried searching "relative hyperlink" in Moodle.org.
Many thanks,
Becky
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
For whatever reason, Moodle was originally written to use absolute links. My suspicion is that the use of the database and the moodledata folder together required absolute paths, but I am not a developer nor do I know much about PHP, so I am probably wrong. To change it would be a massive task and not likely worth the effort.
But.. I would be happy to be proven wrong.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Thank you,
Becky
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Absolute links are an intentional design decision. Here is an example to show why:
Suppose you have a glossary entry that includes a link. Sometimes that is displayed in the glossary (path mod/glossary/something.php) but at other times it might be displayed in the 'random glossary entry' block on the course page (path course/view.php). We want that to work.
Of course, it is also important that you can move content from one place to another in Moodle. The backup and restore system is designed to do that. When you do a restore, it finds all the absolute links, and rewrites them to point at the corresponding place in the new coures. That is actually quite easy with absolute links, you just have to search for $CFG->wwwroot from config.php. With absolute links, every link is guaranteed to contain that. The computation of the correct replacement is a little bit harder, but only a little bit.
Occasionally, we find there is some place where links do not get rewritten properly. If you have a link that is not being correctly rewritten on backup and restore, please report it to the bug Tracker. These things are normally easy to fix once they have been found.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Tim,
Thank you for your response and for all the work you do on the Moodle project. I very much appreciate your work and that of the rest of the Moodle volunteers!
I'm having trouble with this on two fronts. I can understand problems with the one (but was hoping it would be different) but am flummoxed as to the cause on the second.
I use the Flexpage module so I have multiple pages in the course. On the front page, I use icons in the Main Menu. I'd like to link the Discussions icon to the Discussions page in my course. When I restore into a new course, the link takes me to Discussions in the original course instead of Discussions in the new course. Likewise, for Course News and the Help! Forum. I think the Quizzes were fine but my tech guy fixed some of this for me. His fixes might have included Quizzes. I just don't remember at the moment.
The second class of trouble is with images. I upload the images and then make a link to them. Some of them make it from one course to another. Others don't and I have to reupload them. Then, on the next restore, the same images are broken again. I don't know if this is something I have done wrong or if it should go into the bug tracker. Those img_src tags seem to point back to the original place (an absolute link) instead of to a new course.
I was asking about relative/absolute links because I was hoping there was something I could do at the UI level to handle these problems. Our tech guy can fix them when I hand over new courses but he has more urgent things to do than to clean up courses I develop. And, I am not competent to mess with PHP!
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Flex-page is a third-party plugin. From your description, it sounds like they have not implemented backup-and-restore correctly. Try contacting the maintainers of that course format.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Thanks, Tim. I'll post my question in the Flexpage forum. Michael Penney (lead developer) frequents the forum.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
I'm with you Becky. It's a major headache to have to change lots of intralinks when a new course is set up using a Master Course.
This was something which could be done easily in Angel (owned by Blackboard). In Angel once an intralink was put in a Master Course, it remained valid for each new class using that Master Course. Surely the Moodle gurus are as smart as those in Angel . . . . or not.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Thank You. This is very useful.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
I found this interesting as I have just started using relative links for those type of connections (links to Moodle activities/resources). When I link in the html area, I paste in the URL, delete all from "http://" to "/mod" and replace with ".."
So, http://moodle.myserver.com/mod/forum/view.php?id=5892
becomes: ../forum/view.php?id=5892
This seems to work properly, as this way these refer to the current root instead of the originating course root.
Perhaps I'm messing up something that I haven't run across yet.
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
Hi Melinda
my understanding (based on experience and confirmed by reading this forum) is that the issue arises when you backup and restore the course to a new course.
Janine
Re: How do I make relative hyperlinks rather than absolute hyperlinks?
For every courses we are using a tmrepo( teacher tools ) block for teacher only. And creates a widgets block for teacher and students. These blocks will be open in new pop up window on any level of courses.
Step 1: On the root folder of server upload the files.
Example. If you are using Linux then put widgets and tmrepo folders in var/www/
If you are using Windows then put widgets and tmrepo folders in xampp/htdocs
Step 2: Create a new html block(tfw) for tmrepo each and every course.
Step 3: On creation block insert the following code in content area.
<script type="text/javascript">// <![CDATA[
function math2(c) {
var c;
var math2URL = window.location.protocol+"//"+window.location.host+"/tmrepo/tfw/"+c;
return math2URL;
}
// ]]></script>
<p><a href="#" onclick="window.open(math2('Class2/MAT/MAT_C2_Overview.pdf'),'popup','width=600,height=800,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0'); return false">Overview</a></p>
Select the Any Page option in Display on page types.
enjoy it.
Note: Function math2() should be unique in a moodle instance.