# How to edit haml in radiant core?

**URL:** <https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013>\
**Category:** Radiant CMS\
**Created:** [September 8, 2008, 10:10am UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013 "2008-09-08T10:10:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 10:10am UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/1 "2008-09-08T10:10:12Z")

</div>

Hello,

My goal is to use only extensions, and don’t modify radiant core.  
I will try to be clear with an example. I would like to customize the  
avalaible layout list when you are creating / editing a page.  
But it’s not possible, because the request is done directly in  
views/admin/page/edit.html.haml (there is not a var which could be  
change by an extension…).  
How could I do that?

Here is the code :

- render\_region :parts\_bottom do |parts\_bottom|
  - parts\_bottom.edit\_layout\_and\_type do  
.row  
%p  
%label{:for=\>“page\_layout\_id”}  
Layout  
= select “page”, “layout\_id”, [[’’, ‘’]] +  
Layout.find(:all).map { |s| [s.name, s.id] }

I would like to give an other layout list without removing these lines?  
(and I wouldn’t like to hide them with javascript).

What is the best way to do that?

Thank you,  
Vincent

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/2 "2008-09-08T13:24:12Z")

</div>

I’m not sure I understand exactly what you want to do, but I think  
this should do it:

In your whatever\_extension.rb activate method do:

admit.page.edit.add :parts\_bottom, ‘your\_additional\_partial’, :after  
=\> ‘edit\_layout\_and\_type’

Then it will look for a file in ‘vendor/extensions/whatever/app/views/  
admin/page/your\_additional\_partial’ to inject into the interface.

I described the process in the help extension. If it’s a new instance  
of Radiant (or is running on edge) just run ‘script/extension install  
help’  
or if you have the Ray extension  
[http://github.com/johnmuhl/radiant-ray-extension/tree/master](http://github.com/johnmuhl/radiant-ray-extension/tree/master)  
run ‘rake ray:help’  
or take a look at the Help docs directly at

> <https://github.com/saturnflyer/radiant-help-extension/blob/master/HELP_developer.rdoc>

and read the ‘Partial Injection’ area. It applies to the way this  
works in the rest of the application as well.  
You can also read [http://wiki.radiantcms.org/](http://wiki.radiantcms.org/)  
Using\_the\_Shards\_Extension (the Shards extension is now part of the  
core, so you can ignore the installation and configuration details)

If you want to alter the list of Layouts the Help extension provides a  
‘replace’ method for the admin UI that you could use to completely  
change the default list of Layouts.

Does that answer your question?

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/3 "2008-09-08T13:46:26Z")

</div>

Hello Jim,

I had already use shards to inject and extend functionnalities to pages,  
it’s not a problem.  
Here, I would like to remove or replace an ‘existing’ part : layout  
list, to replace it by my list for example.

I didn’t see we can ‘replace’ a part, thank you.  
Do you have any documentation about the replace method?  
What does it looks like?

Thank you !  
Vincent

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/4 "2008-09-08T14:51:53Z")

</div>

It works just like the ‘add’ method. I have this in the Help extension:  
Radiant::AdminUI::RegionSet.class\_eval do  
def replace(region=nil, partial=nil)  
raise ArgumentError, “You must specify a region and a  
partial” unless region and partial  
self[region].replace([partial])  
end  
end  
So you can just do

admin.page.edit.replace :the\_part, ‘my\_part’

The only documentation is where I implemented it

> <https://github.com/saturnflyer/radiant-help-extension/blob/6b691a675955bdf934ebba7f3ec6bf3142094b90/help_extension.rb>

Although, now that I look at it, I realize that this is pointless  
because you can just create a partial of the same name and Radiant  
will pick it up.  
So just create a partial in your extension in ‘app/views/admin/page/  
edit\_layout\_and\_type’ and It will be picked up instead of the default.

Sorry for the long-winded response.

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/5 "2008-09-08T15:55:32Z")

</div>

Jim G. wrote:

> admin.page.edit.replace :the\_part, ‘my\_part’  
> instead of the default.
> 
> Sorry for the long-winded response.  
> Yes, or since regions are just arrays on the admin object, you can  
> remove the offending one and replace it with your own. These two lines  
> do that in the concurrent\_draft extension (where view is one of page,  
> snippet, or layout):

```
  admin.send(view).edit.form_bottom.delete 'edit_buttons'
  admin.send(view).edit.add :form_bottom, 'admin/edit_buttons'

```

Sean

---

<div class="post-metadata">

**Author:** ![vpredoehl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/67e7ee/32.png) [@vpredoehl](https://www.ruby-forum.com/u/vpredoehl)\
**Post date:** [September 8, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/how-to-edit-haml-in-radiant-core/148013/6 "2008-09-08T15:58:27Z")

</div>

That’s just perfect !  
I created a file named \_edit\_layout\_and\_type.rhtml in my extension and  
it’s working !

Thank you, radiant is realy flexible !  
Vincent
