Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

What is the most efficient way to make changes to code in Vanilla?

Having achieved a working understanding of css in Vanilla, I'm looking at trying to get a better understanding of efficient ways to change some of the php code.

As an example:

I want to change this line in \applications\vanilla\views\post\comment.php

echo Anchor($CancelText, '/');

to

echo Anchor($CancelText, '/discussions');

I can achieve this by copying the whole of the comment.php file to my theme views\post folder, and making the change there, but I can't help but feel there is a cleaner solution.

What say you, code gurus?

Tagged:

Comments

  • x00x00 MVP
    edited July 2013

    If anything I would open up a ticket on github.

    You could create a pluign or themehook that adds another link, but to completely remove it form the markup you would have to copy it across, however you could hide it with css.

    grep is your friend.

  • Hi @x00

    Thanks for the reply.

    I don't want to hide the link, just change where it is pointing to.

    I've achieved this by copying and editing the comment.php file in my theme, I just wondered if there were a more efficient way of making the same change.

  • I suppose you are using vanilla greater than 2.0.18

    Aside from the way you suggested, I don't know if there is a clean way except for jQuery

    to select for span class (Back or Cancel or definitions) and change Anchor url

    or select for anchor with a specific text (Cancel or Home or whatever you changed definition from) and change the anchor url

    and put the jquery in your theme hooks.

    it would be interesting to here what others have to say

    e.g.

    jQuery(document).ready(function($) {
    $(".Back a").attr("href","/discussions");
    })

    or

    jQuery(document).ready(function($) {
    $(".Cancel a").attr("href","/discussions");
    })

    or

    jQuery(document).ready(function($) {
    $(".Back a").attr("href","/discussions");
    $(".Cancel a").attr("href","/discussions");
    })

    if it doesn't work you may need to make it live.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Sorry, @peregrine

    Yes, I am using 2.1b1

    Am I right in assuming I would put that code in a .js file and call it via themehook?

  • peregrineperegrine MVP
    edited July 2013

    Yes, you could add it based on event

    DiscussionController_AfterFormButtons_Handler

    or whatever event shows up

    or maybe something like this

    $('.Back a').live('click', function(e) {
    $(this).attr("href","/discussions");
    });

    you'd need to play around a bit.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • if you don't have to use live don't use it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • unfortunately when doing new discussion

    PostController_AfterFormButtons_Handler

    comes before the cancel button - this may be intentional or an oversight.

    but in posting comments it should work without live.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Cheers @peregrine

    I shall have a play tomorrow.

  • This is the perfect time to use a view override (copying the view over and changing it to suit your needs like you are now).

    That said, this view is often retrieved via AJAX and the cancel button is hooked into removing the form on click.

    In the case of the view being a "standalone" page, I would suggest a sensible default for the cancel button would be to return to the discussion being commented on.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Cheers @hgtonight

    Just wondered if I was missing an obvious alternative.

Sign In or Register to comment.