Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3624338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:29:43+00:00 2026-05-18T23:29:43+00:00

Hello Friends I am a newbie programmer and very very new to PHP. I

  • 0

Hello Friends I am a newbie programmer and very very new to PHP. I am seeking help in writing a small php Function. The situation is like this:

I am running Joomla and I have a template which is in BLOCKS for example:

header.php
topmodules.php
mainbody.php
bottommodules.php
footer.php

All my blocks are placed in a directory (/layouts/blocks). All these blocks need to be joined in the main Index.php file.

The function I know is something like this:

<?php
function get_header(){
  require_once(TEMPLATEPATH.'/layouts/blocks/header.php');
}
?>

And then call it like:

<?php get_header(); ?>

But that is not very professional and also I will have to write a function for every file moreover this can also be accomplished by just using

<?php require(YOURBASEPATH . DS .'layouts'. DS .'blocks'. DS . "header.php"); ?>

But what I am looking for is to have a single function /class which can get that PHP file from that directory, just by passing the name of the file so that I can add some more blocks to that directory in future without re-writing the function and simply call them like:

<?php $this->getBlock('header') ?>
<?php $this->getBlock('topmodules') ?>
<?php $this->getBlock('mainbody') ?>
<?php $this->getBlock('bottommodules') ?>
<?php $this->getBlock('footer') ?>

Kindly help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:29:44+00:00Added an answer on May 18, 2026 at 11:29 pm

    You just need to add a parameter to the function you have:

    function getBlock($filename){
      require_once(YOURBASEPATH . DS . 'layouts' .DS . 'blocks'. DS . $filename .'.php');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends a newbie question... The Issue is like this: I have a static
Hello friends a very novice question as I am very new to programming. I
Hello future friends who is gonna help me big time on this project, I
hello friends i m new to jQuery and nyro modal. right now i m
Hello friends i am running code given below which contains the setLogTimeEntery function and
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
Hello friends I am using this code in my view.. Using this code I
hello friends i am using this galleria gallery link to display images on my
Hello friends I have the following script in my Template: window.addEvent('domready', function () {
hello friends I am newbie to Yii.I have the date and time in mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.