I'm developing my first custom module and I need some help with it.

When a user is clicking on the following

<a download=”filename.docx” href="exporttoword/567?xml=/xmlcv&template=/internal.xsl&output=filename.docx" >Export to Word</a>

then the user should recieve a word document from his node.

I used the hooks_menu. I do not know why. So based on examples it is like this:

function foo_menu() {
  $items = array();
  $items['exportoword/%'] = array(
    'title' => 'Export to Word',
    'type' => MENU_CALLBACK,
    'page callback' => 'convert_to_word',
    'access arguments' => array('access content'),
  return $items;

And the of course the function itself.

function convert_to_word ($args = 'all') {

// HOW TO GET THESE argument here?
// NodeId           567
// Pathtoxml        /xmlcv
// Pathtotemplate   internal.xsl
// FileToSave       filename.docx

// Get the NodeID XML from /xmlcv/576
$xml = new DOMDocument;
$xml-> file_get_contents( $pathtoxml & '/' &$nodeid );

// Load XSL file from the template location
$xsl = new DOMDocument;

// Configure the transformer
$proc = new XSLTProcessor;

// Attach the xsl rules

// Process it

// Document is now in XHTMl. Somehow convert to .docx

// No clue yet... 
// shell converting or just rename the file and push back to customer?
//  $output = shell_exec('pandoc -s -S README -o example29.docx');
// Save it to a file on the server or do I return the file?

 file_put_contents($FileToSave, $proc);

return 'success

How to get the arguments as parameters in the convert_to_word function?

  • Hi, I removed the extra questions (please ask each individual question separately). For your remaining question - have you read the docs for hook_menu? There are several examples on there. If you don't know how to get the URL parameters, they're not part of the route so use $_GET to access them
    – Clive
    Jun 24, 2016 at 12:57
  • Actually we have a completely exhaustive Q/A for this already, you'll find everything you need to know in the duplicate
    – Clive
    Jun 24, 2016 at 13:01


Browse other questions tagged or ask your own question.