Virtual Pages via Extension

I’m about to start work on an extension where I need to create my own
virtual page type. I’m more than a little confused about them and am
not sure where to start. (As I leave charted waters, my map just reads:
“There be dragons here”).

Anybody able to point me to some documentation or some good sample code
that might give me a leg up in this area?

Specifically, what I’m looking to do is allow the user to create a
virtual page that renders a list view (say, ‘/recipes’) based on dynamic
data in the db. But I also want this page to automatically have it’s
own virtual children rendering as an item view (like,
‘/recipes/apple-pie’ & ‘/recipes/chicken-gumbo’).

-Chris

I can be a little confusing at first, but for the basics of virtual
pages, I’d check out the ArchivePage types. The pages themselves are
in vendor/app/models/archive*.rb but probably the most important part
is is the module in vendor/radiant/lib/archive_index_tag which is
included in all of the virtual archive pages.

The easiest way to do what you’re trying to do would be to make two
new page types: one that’s the parent of the virtual page which acts
as an index (RecipeListPage) and another that’s the actual virtual
page (RecipePage).

In RecipeListPage, you may want to override child_url and find_by_url
as in ArchivePage.

In RecipePage, you can override find_by_url to query for the recipe
record and save it as an instance variable which will be available
later. You’ll also want to override render to handle the Recipe
objects instead of rendering the PageParts like normal. You’ll also
want to override virtual? to return true and probably do something
with title as well.

Sorry if this wasn’t too detailed. I’d recommend maybe stepping
through the URL matching and render code with ruby-debug if you want
to get a better idea of how things work. Here’s a good tutorial on
ruby-debug:

-Andrew

Agh! Should have proofread…

The module is in vendor/radiant/lib/archive_index_tags_and_methods.rb

Andrew O’Brien wrote:

Agh! Should have proofread…

Personally, I like the bit where you say…

I can be a little confusing at first, but…
:wink:

Thanks for the quick replies, guys.

-Chris

Chris,

Also have a look at the files at this URL:

That’s the code from an extension I wrote last year for KCKCC. It
essentially does what Andrew describes, for the custom models in the
extension, which are Prefix, Course, and Syllabus. There’s also more
detail in the tags at

http://kck.esumm.com/www/html/vendor/extensions/syllabi/lib/

Feel free to browse around that URL for any of the code I wrote for the
college. Keep in mind that most of it is about a year old, so it may
not function directly with Radiant’s current form.

Sean