2

I'm pretty new to magento and I would like to customize the store front-end.

I'm using Magento 1.4.1 and I'm planning to do all design modifications on the local.xml of my new template.

My doubt is if it is possible to change the layout structure only using the local.xml. I mean without changing the phtml files.

A simple example of what I would like to be able is: I want to put the catalog search in another part of my html and not inside the , as it is today. So I would like to remove it from top-bar and put it inside another div.

<div class="top-bar">
<div class="breadcrumbs">
    <ul>
                    <li class="home">
                            <a href="http://www.domain.com/magento/" title="Ir para página principal">Principal</a>
                                        <span>/ </span>
                        </li>
                    <li class="category9">
                            <strong>Product Category</strong>
                                    </li>
            </ul>
</div><!--breadcrumbs-->
<form id="search_mini_form" action="http://www.domain.com/magento/catalogsearch/result/" method="get">
    <div class="form-search">
        <label for="search">Pesquisar</label>
        <input id="search" type="text" name="q" value="" class="input-text" />
        <button type="submit" title="Ir" class="button"><span><span>Ir</span></span></button>
        <div id="search_autocomplete" class="search-autocomplete"></div>
        <script type="text/javascript">
        //<![CDATA[
            var searchForm = new Varien.searchForm('search_mini_form', 'search', 'Procurar em toda a loja...');
            searchForm.initAutocomplete('http://www.domain.com/magento/catalogsearch/ajax/suggest/', 'search_autocomplete');
        //]]>
        </script>
    </div>
</form>
</div>   <!--top bar-->

How do I accomplish this? Is it possible to use only local.xml?

Thanks in advance and best regards

1 Answer 1

3

The practical answer is "No, you can't do that".

What you want to do is theoretically possible, although the amount of work that would need to be done and the value of it would be questionable.  

You use local.xml to add, remove, and interact with Blocks.  Each phtml file has a parent block that corresponds to something in your layout.  You can't change how a phtml block is rendered via the Layout XML, unless the Block and phtml contain logic to allow this.

In theory, you could

  1. Identify the class responsible for rendering a particular template
  2. Create a new Block class that extends this class (not override)
  3. Change add code in local.xml to replace the block class 
  4. In your new block class override the view rendering method so it calls the parent view rendering method, and then attempts to alter the results of the returned string before returning its value

Again, all possible, but of questionable value.

Why the hesitancy to replace a phtml file from the default theme with a phtml file in your own theme(s)?

Sign up to request clarification or add additional context in comments.

3 Comments

great. Thanks for you anwser. I believed this was the right way of doing it, so that upgrades were transparent and without issues. But it seems that I still have to change phtml for structural html changes. :)
When people on the forums (etc) talk about it sometimes they make it seem like it is possible to be 100% upgrade proof - I think that is fantasy, except for special cases where there minimal changes are being done.
And just to offer a (common) solution.... In addition to the local.xml method, I don't ever touch the stock phtml files, but rather I copy them and put them into my own theme folder to make the modifications. That way it is easy to see which changes I have made to the default with a diff. Also, when I upgrade to the next version of magento I can see which phtml files were updated in the default theme and compare to my customized phtml files. (my method assumes some type of scm like mercurial/git/etc to be able to do diffs though)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.