How can I include the course number from the url,
In the src for an iframe on the page?
I suspect there's more to your question than what you asked, so I imagine this is not the answer you're looking for. As it reads, you can just copy the course ID from the URL in your browser and supply it when you create the source. Often you can just copy/paste from the browser.
That sounds too simplistic and most people do not embed content from within their Canvas course within content within their Canvas course. Yes, I know that sounds recursive and terribly confusing, which is what you get when you try this, a double set of menus and everything else -- nested iframe hell.
Let's say that I want to embed the following PDF in a page. It's under the Textbook folder in my course files.
The first method is to go to Files and find the file that you want and click on it to pull up the preview. When I do that with this PDF file, I get something this URL.
You can use that URL as the src for your iframe.
You can also remove the /folder/Textbook and just use the URL
There is currently an issue with doing things this way, though. I don't know if it's considered a bug or not, but at the time I write this if you upload a file and replace it with a newer version, the previews will stop working as the file ID changes. If the file ID is part of the route (path), then it gets updated, but not when it's part of the query string (preview=id). Here's what I get when that happens:
If you look closely, you can see the Canvas navigation in the background. That's what I was talking about with the issue of embedding Canvas content within Canvas content -- except if it wasn't a file, then it wouldn't be grayed out.
Even though I couldn't get it to work with the PDF file, I'll go ahead and show you what it looks like. The trick is to use the file_contents/ route in the URL and then give the case-sensitive path to the file, encoding the URL (replace spaces with %20). In this case, the root folder is called "course files" so that gets encoded as "course%20files".
In general, though, it is not encouraged to embed content from within Canvas inside an iframe. Instead, you may want to consider making the content available as a link on the page by using the Rich Content Sidebar, where you can just pick it from the menu. If you use modules, then you can add the file as a module item.
If your question was about automatically including the course number, then you can't. This might be your question if you're taking content that was developed for a web page where you have relative URLs and you're trying to recreate that within Canvas but found that it won't work to just use "/" to refer to the root of the course. However, you can use a relative URL that begins with '../' to move from where you are to where you want to be. Let's say that the URL to your page where you want to do the embed is at:
Then this iframe source would work (the newlocation.html is an HTML file, which I could get to work -- remember I couldn't get the PDF to embed this way).
The ../ moves up a parent folder, so it moves from /courses/896851/pages/ to /courses/896851/ and then you can specify the rest of the URL. In this way, you don't need the course ID.
Hopefully that helps, but I wasn't sure from the question what you were trying to accomplish. Sometimes people can provide better answers when we know why you're trying to do something rather than the mechanics of a specific portion of it.
First, let me say instructure is super lucky to have an advocate like yourself. That answer was amazing!
So what I'm looking to do is include a PHP page and pass the course number as a get variable to that PHP page. (This PHP page accepts the data and sends it different places) The PHP page resides on a different university system. Based on your answer, I'm thinking this isn't easily done and I might start looking into using the API to accomplish what I need. Do you think this would be possible with the API?
Hey Andrew Bowns,
It sounds like what you're trying to do is awfully similar to what LTI is designed to do. Have you considered simply writing your PHP app to be an LTI provider instead of leveraging JS+API+PHP to achieve this?
and then parsing with `split()` or whatever method you like. The downside is that the PHP script is rendered on the server side, loaded in the iframe, then your JS will run and provie data to the PHP script, so you'll then either have to re-post and refresh or use AJAX to fire off some stuff. LTI seems better IMO as all that data is passed during the initial OAuth POST.
See what Danny Wahl wrote -- LTI is the easiest way to accomplish that and if the course ID is all that you need, then you won't need to mess with API. If there is something else, there's a good chance it's included as a custom variable -- see Variable Substitution in the API documentation. There are libraries available for PHP (and other languages) that make handling the LTI stuff much less difficult. If you do need to use the API, you can have that other system make the calls for you.
Sorry I couldn't figure out what you wanted to do with the first message or I would have suggested LTI in the first response.
Were you able to find an answer to your question? I am going to go ahead and mark this question as answered because there hasn't been any more activity in a while so I assume that you have the information that you need. If you still have a question about this or if you have information that you would like to share with the community, by all means, please do come back and leave a comment. Also, if this question has been answered by one of the previous replies, please feel free to mark that answer as correct.
Retrieving data ...