# Virtual Pages via Extension

**URL:** <https://www.ruby-forum.com/t/virtual-pages-via-extension/119682>\
**Category:** Radiant CMS\
**Created:** [November 9, 2007, 6:20am UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682 "2007-11-09T06:20:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [November 9, 2007, 6:20am UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682/1 "2007-11-09T06:20:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [November 9, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682/2 "2007-11-09T15:15:43Z")

</div>

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:

> **[DATANOISE.COM](https://www.datanoise.com/)**
>
> DATANOISE.COM - Contact us for any business inquiries

-Andrew

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [November 9, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682/3 "2007-11-09T15:17:28Z")

</div>

Agh! Should have proofread…

The module is in vendor/radiant/lib/archive\_index\_tags\_and\_methods.rb

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [November 9, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682/4 "2007-11-09T15:46:55Z")

</div>

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…  
> > 😉

Thanks for the quick replies, guys.

-Chris

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [November 9, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/virtual-pages-via-extension/119682/5 "2007-11-09T15:28:02Z")

</div>

Chris,

Also have a look at the files at this URL:

> **[Esumm.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=esumm.com)**
>
> Get this domain name before someone else does. Quick and painless shopping. Affordable payment options available.

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/](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
