member resources - open in new window (_blank)

Discussion in 'Customization & add-ons' started by jalbrecht, Sep 12, 2014.

  1. jalbrecht

    jalbrecht New Member

    Joined:
    Apr 27, 2014
    Messages:
    3
    How can i change this part of member_main_resources.phtml, that a click on a resource open in new window?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can edit file amember/application/default/models/ResourceAbstract.php find method renderLink and add target="_blank" to link code.
  3. jalbrecht

    jalbrecht New Member

    Joined:
    Apr 27, 2014
    Messages:
    3
    thank u - that works but finally also let the member links open in a new window. is it possible that only the member resources open in new window?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    What do you mean member links? These changes should affect only resources. May be you can attach screenshot and highlight what is exact link open in new window besides resources after these changes.
  5. gary_gus

    gary_gus aMember Pro Customer

    Joined:
    Aug 29, 2006
    Messages:
    2
    Won't this get over written on updates ResourceAbstract.php
    Can't we override this function somewhere to prevent losing the changes?
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Yeah, you are right. It is not good idea to alter core files because it will make upgrades difficult in future.
    Here is better solution for this case. This approach is upgrade proof. You need to put the following code to site.php file (http://www.amember.com/docs/Site.php_file):

    Code:
    Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, function(Am_Event_AfterRender $e){
        if (preg_match('|blocks/member-main-resources\.phtml$|i', $e->getTemplateName())) {
            $e->replace('/(<a)/', '$1 target="_blank" ');
        }
    });
    We improve aMember every day and I believe aMember is not just script but it is membership platform. aMember is very flexible and allow to change almost every aspect of software without touch any core file. It give you great power to customize your installation according your exact requirements but still have ability to take advantage from easy upgrades to upcoming versions.
  7. halmaclean

    halmaclean aMember Pro Customer

    Joined:
    Aug 30, 2013
    Messages:
    50
    csesar - that's a neat solution, but doesn't work if you check the box to hide the link on the Dashboard, and put it in a content category instead. I'd like the links listed on the resulting content category page to open in a new window. Is there an equally simple way to achieve that?
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Here is code for resource category pages:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::AFTER_RENDER, function(Am_Event_AfterRender $e){
      if (
    preg_match('|member/category\.phtml|i'$e->getTemplateName())) {
          
    $e->replace('/(<a) (id="resource-link)/''$1 target="_blank" $2');
      }
    });
    relapse likes this.

Share This Page